SLIDE 3 3
Family Tree
Age old quest ions – wher e do new pr ocesses come
f rom?
New pr ocesses ar e cr eat ed when an exist ing
pr ocess r equest s it
Creat ing process called t he parent ; creat ed called t he
child
Children of same parent called siblings
Childr en of t en inher it pr ivileges/ at t r ibut es f r om
t heir parent
Working direct ory, Clone of address space
When child is cr eat ed, par ent may eit her wait f or
it or cont inue in par allel
pst ree
init - +- 1 8*[ Xvnc] | - amd | - at d | - bdf lush | - crond | - 1 6*[ deskguide_apple] | - 8*[ gconf d- 1] | - gedit | - 18*[gnome- name- serv] | - 16*[gnome- session] | - 16*[gnome- smproxy] | - gnome- t erminal- +- csh---gt op | ` - gnome- pt y- helpe | - gnome- t erminal- +- csh- +
| | ` - t csh | ` - gnome- pt y- helpe | - gnome- t erminal- +- csh---t csh--- xt erm- - - csh | ` - gnome- pt y- helpe | - gpm | - 8*[hyperbola] | - kevent d | - khubd | - 5*[ kj ournald] | - klogd | - ksof t irqd_CP U0 | - ksof t irqd_CPU1 | - kswapd | - kupdat ed | - lockd init - +- 1 8*[ Xvnc] | - 1 6*[ magicdev] | - mdrecoveryd | - migrat ion_CP U0 | - migrat ion_CP U1 | - 6*[ minget t y] | - 2*[naut ilus- - - naut ilus
| - 2*[naut ilus- - - naut ilus
| - 3*[naut ilus- - - naut ilus
| - naut ilus- - - naut ilus---7*[naut ilus] | - 7*[naut ilus- hist or] | - naut ilus- mozill- - - naut ilus
- mozill- - - 4*[naut ilus-
mozill] | - 8*[naut ilus- news] | - 8*[naut ilus- not es] | - 7*[naut ilus- t hrobb] | - nt pd | - 1 3*[ oaf d] | - 16*[panel] | - port map | - 1 6*[ rhn- applet ] | - rhn- applet - - - gnome_segv | - rhnsd | - rpc.st at d | - rpciod | - 14*[sawf ish] | - 2*[sawf ish- - -rep] | - scsi_eh_0 | - scsi_eh_1 | - sendmail init - +- 1 8*[ Xvnc] | - sshd- +- 2*[ sshd--- csh--- mc] | | - sshd- - - csh | | - sshd- - - csh- +- more | | ` - net st at | `-sshd---csh ---pst r ee | - syslogd | - 1 6*[ t asklist _applet ] | - xemacs | - xf s- - - xf s | - xinet d- - - f am | - xscreensaver- - - greynet ic | - xscreensaver- - - hopalong | - 2*[ xscreensaver- - - xscreensaver] | - xscreensaver- - - kumppa | - xscreensaver- - - spot light | - xscreensaver- - - spiral | - xscreensaver- - - nerverot | - xscreensaver- - - st range | - xscreensaver- - - f lame | - xscreensaver- - - grav | - xscreensaver- - - light ning | - xscreensaver- - - penet rat e | - xscreensaver- - - rot zoomer---xscreensaver- ge | - xscreensaver- - - deluxe | - xscreensaver- - - rd- bomb | - xscreensaver- - - sonar | - xscreensaver- - - moire2 ` - ypbind- - - ypbind- - - 2*[ ypbind
I nit process
I n last st age of boot pr ocess, ker nel cr eat es a
user level pr ocess, init
I nit is t he par ent (or gr andpar ent …
) of all ot her pr ocesses
I nit does var ious impor t ant housecleaning
act ivit ies
checks and mount s t he f ilesyst ems, set s host name,
t imezones, et c. I nit r eads var ious “r esour ce conf igur at ion f iles”
(/ et c/ rc.conf , et c) and spawns of f pr ocesses t o pr ovide var ious ser vices
I n mult i -user mode, init maint ains processes f or
each t er minal por t ( tty )
Usually runs get t y which execut es t he login program
How is a process represent ed?
Usually a process or t ask obj ect Process Cont rol Block When not running how does t he OS
remember everyt hing needed t o st art t his j ob r unning again
Regist er s, St at ist ics, Wor king dir ect or y, Open
f iles, User who owns pr ocess, Timer s, Par ent Pr ocess and sibling pr ocess ids I n Linux, t ask_st ruct def ined in
include/ linux/ sched.h
struct task_struct { /* these are hardcoded- don't touch */ volatile long state; /*
- 1 unrunnable, 0runnable, >0
stopped */ long counter; long priority; unsigned long signal; unsigned long blocked; /* bitmap of masked signals */ unsigned long flags; /* per process flags, defined below */ int errno; long debugreg[8]; /* Hardware debugging registers */ struct exec_domain *exec_domain; /* various fields */ struct linux_binfmt*binfmt; struct task_struct *next_task, * prev_task; struct task_struct *next_run, * prev_run; unsigned long saved_kernel_stack; unsigned long kernel_stack_page; int exit_code, exit_signal; /* ??? */ unsigned long personality; int dumpable :1; int did_exec:1; /* shouldn't this be pid _t? */ int pid; int pgrp; int tty_old_pgrp; int session; /* boolean value for session group leader */ int leader; int groups[NGROUPS]; /* * pointers to (original) parent process, youngest child, younger sibling, * older sibling,
- respectively. (p ->father can be replaced with * p-
>p_pptr ->pid ) */ struct task_struct *p_opptr, *p_ pptr, *p_cptr , *p_ysptr, *p_osptr; struct wait_queue *wait_chldexit; /* for wait4() */ unsigned short uid,euid ,suid,fsuid; unsigned short gid,egid ,sgid,fsgid; unsigned long timeout, policy, rt_priority; unsigned long it_real_value, it_prof_value, it_virt_value; unsigned long it_real_incr , it_prof_incr, it_virt_incr; struct timer_list real_timer; long utime, stime , cutime, cstime , start_time; /* mm fault and swap info: this can arguably be seen as either mm-specific or thread -specific */ unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap; int swappable:1; unsigned long swap_address; unsigned long old_maj_ flt; /* old value of maj_flt */ unsigned long dec_flt; /* page fault count of the last time */ unsigned long swap_cnt; /* number of pages to swap on next pass */ /* limits */ struct rlimit rlim[RLIM_NLIMITS]; unsigned short used_math; char comm[16]; /* file system info */ int link_count; struct tty_struct *tty; /* NULL if no tty */ /* ipc stuff */ struct sem_undo * semundo ; struct sem_queue *semsleeping; /* ldt for this task - used by Wine. If NULL, default_ldt is used */ struct desc_struct *ldt; /* tss for this task */ struct thread_struct tss; /* filesystem information */ struct fs_struct *fs; /* open file information */ struct files_struct *files; /* memory management info */ struct mm_struct *mm; /* signal handlers */ struct signal_struct *sig; #ifdef __SMP__ int processor; int last_processor; int lock_depth; /* Lock depth. We can context switch in and out of holding asyscall kernel lock... */ #endif };
Management of P CBs
PCBs ar e dat a st r uct ur es (j ust like you ar e used t o
at user level)
Space f or t hem may be dynamically allocat ed as
needed or per haps a f ixed sized ar r ay of PCBs f or t he maximum number of possible pr ocesses is allocat ed at init t ime
As pr ocess is cr eat ed, a PCB is assigned and
init ialized f or it
Of t en process id is an of f set int o an array of P
CBs Af t er pr ocess t er minat es, PCB is f r eed
(somet imes kept ar ound f or par ent t o r et r ieve it s exit st at us)