Lesson 3. Processes in Linux

Introduction. The process table

Juan Carlos Pérez y Sergio Sáez
Sergio Sáez
Juan Carlos Pérez
ssaez@disca.upv.es
jcperez@disca.upv.es

3.1 Structure of a process in Linux


3.2 The process table


Many parts of the Operating System use both data structures, therefore it is important to know some of the most important fields in them.

We are going to study som of the fields of task_struct.


3.3 The task_struct structure

Some of these fields are:

include/linux/sched.h [528-536]
 528 struct task_struct {
 529         volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
 530         struct thread_info *thread_info;
 531         atomic_t usage;
 532         unsigned long flags;    /* per process flags, defined below */
 533         unsigned long ptrace;
 534 
 535         int lock_depth;         /* Lock depth */
 536 


3.3.1 Fields for scheduling

There is a set of fields that are used by one of the main functions of the scheduler code and that appear consecutively in task_struct so as they fit in a single cache line.

include/linux/sched.h [537-547,595]
 537         int prio, static_prio;
 538         struct list_head run_list;
 539         prio_array_t *array;
 540 
 541         unsigned long sleep_avg;
 542         unsigned long long timestamp, last_ran;
 543         int activated;
 544 
 545         unsigned long policy;
 546         cpumask_t cpus_allowed;
 547         unsigned int time_slice, first_time_slice;
...
 595         unsigned long rt_priority;




3.3.2 Other fields related to scheduling

Other interesting fields in the task_struct are:

include/linux/sched.h [553,561]
 553         struct list_head tasks;
...
 561         struct mm_struct *mm, *active_mm;


3.3.3 General information about the process

Other fields containing general use information on the process are:

include/linux/sched.h [565-566,571-572,606-607]
 565         long exit_state;
 566         int exit_code, exit_signal;
...
 571         pid_t pid;
 572         pid_t tgid;
...
 606         uid_t uid,euid,suid,fsuid;
 607         gid_t gid,egid,sgid,fsgid;


3.3.4 Relations among processes

Fields that contain information on the relations among processes

include/linux/sched.h [573-586]
 573         /* 
 574          * pointers to (original) parent process, youngest child, younger sibling,
 575          * older sibling, respectively.  (p->father can be replaced with 
 576          * p->parent->pid)
 577          */
 578         struct task_struct *real_parent; /* real parent process (when being debugged) */
 579         struct task_struct *parent;     /* parent process */
 580         /*
 581          * children/sibling forms the list of my children plus the
 582          * tasks I'm ptracing.
 583          */
 584         struct list_head children;      /* list of my children */
 585         struct list_head sibling;       /* linkage in my parent's children list */
 586         struct task_struct *group_leader;       /* threadgroup leader */

There are many other fields, some of which we will mention when they are used in the code.