LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2008, 03:18 PM   #1
LinuxInfo
LQ Newbie
 
Registered: Sep 2008
Posts: 21

Rep: Reputation: 15
I need to know the reason why 'State' has been declared as 'Long' in Linux PCB.


Dear Sir,

Please refer to the following Linux PCB code and let me know why State has been declared Long.

/* memory management info */
struct mm_struct *mm;
/* open file information */
struct files_struct *files;
/* tss for this task */
struct thread_struct tss;
int pid;
volatile long state; /* -1
unrunnable, 0 runnable, >0 stopped
*/
long priority;
unsigned short uid,euid,suid,fsuid;
#ifdef __SMP__
int processor;
#endif
struct task_struct *p_opptr, *p_pptr,
*p_cptr, *p_ysptr, *p_osptr;
/* limits */
struct rlimit rlim[RLIM_NLIMITS];
long utime, stime, cutime, cstime,
start_time;
 
Old 09-15-2008, 05:01 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
You'll have to look at how 'state' is used to find out. 'long' is typically used for a variable which may be 32-bit on a 32-bit CPU and 64-bit on a 64-bit CPU (at least GCC allows this behavior).
 
Old 09-15-2008, 09:30 PM   #3
LinuxInfo
LQ Newbie
 
Registered: Sep 2008
Posts: 21

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pinniped View Post
You'll have to look at how 'state' is used to find out. 'long' is typically used for a variable which may be 32-bit on a 32-bit CPU and 64-bit on a 64-bit CPU (at least GCC allows this behavior).
Thanks for the reply.

But please see the below code:

struct task_struct{
long state; /*0 for dispatchable*/ pid_t pid;
long priority;
unsigned long signal;
unsigned long blocked;
unsigned long flags;

Here we could also have taken int as we might be using 0 value or we could also have taken Double but it seems like there is a reason we used Long everywhere. Please if anyone could answer me this, it will be a great help to me.

Thanks.

Last edited by LinuxInfo; 09-15-2008 at 09:37 PM.
 
Old 09-15-2008, 11:14 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Well since it is used as a flag then an integer type (rather than a float) makes sense. Since the comment indicates >0 maybe the use of long is to avoid an overflow problem. To confirm this you will need to look into the code.
 
Old 09-16-2008, 12:02 AM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
long is used to maintain architecture alignment; as mentioned, this will be 32-bit on 32-bit platforms, and 64-bit on 64-bit platforms. If int were used, 64-bit platforms would be accessing unaligned data (relative to register size).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: State by state, Microsoft responds to creeping threat LXer Syndicated Linux News 0 05-01-2007 07:16 AM
good PCB designing software? bobbens Linux - Software 2 01-11-2005 02:05 PM
PCB and broken pipe jm31 Linux - Software 0 09-12-2004 12:20 PM
Criterion Aptos pcb layout program barrys Linux - Software 0 07-29-2004 07:29 AM
running pcb design software in linux?? xbong_x Mandriva 4 02-24-2004 06:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration