220 likes | 435 Views
Process. init_task idle init pid : 1 task process, thread copy on write. Task Structure. include/kernel/sched.h struct task_strcut { …} ; struct task_struct * next_task, * prev_task ; struct task_struct * next_run, * prev_run ; struct task_struct * p_opptr, * p_pptr,
E N D
init_task idle • init pid : 1 • task process, thread • copy on write
Task Structure • include/kernel/sched.h • struct task_strcut { …} ; • struct task_struct * next_task, * prev_task ; • struct task_struct * next_run, * prev_run ; • struct task_struct * p_opptr, * p_pptr, * p_cptr, * p_ysptr, * p_osptr ;
parent p_cptr p_pptr p_pptr p_pptr p_osptr p_osptr oldest child youngest child child p_ysptr p_ysptr
volatile long state ; hardcoded #define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE 1 #define TASK_UNINTERRUPTIBLE 2 #define TASK_ZOMBIE 4 #define TASK_STOPPED 8 #define TASK_SWAPPING 16
unsigned long flags ; hardcoded #define PF_STARTING 0x00000002 /* being created */ #define PF_EXITING 0x00000004 /* getting shut down */ #define PF_PTRACED 0x00000010 /* set if ptrace (0) has been called */ #define PF_TRACESYS 0x00000020 /* tracing system calls */ #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ #define PF_DUMPCORE 0x00000200 /* dumped core */ #define PF_SIGNALED 0x00000400 /* killed by a signal */ #define PF_MEMALLOC 0x00000800 /* Allocating memory */
Identifiers • pid_t pid ; • pid_t pgrp ; • pid_t session ; • int leader ; boolean value session process group process group process group
uid_t uid, euid, suid, fsuid ; • gid_t gid, egid, sgid, fsgid ; • gid_t groups [NGROUPS] ; • int ngroups ;
Scheduling 10ms, tick, jiffies • long counter ; • long priority ; • unsigned long policy, rt_priority ; • SCHED_OTHER • SCHED_FIFO • SCHED_RR weight = 1000 + p -> priority ; weight = p -> counter ; p -> counter = (p counter / 2) + p -> priority ;
SMP (Symmetric Multi-Processing) • int has_cpu ; • int processor ; • int last_processor ; • int lock_depth ; /* Lock depth. We can context switch in and out of holding a syscall kernel lock... */
Files • struct fs_struct * fs ; • struct files_struct * files ;
fs_struct inode task_struct inode files_struct file inode
Virtual Memory • struct mm_struct * mm ; • demand paging • list, AVL tree
vm_area_struct task_struct mm_struct Process Virtual Memory 0x8059BB8 vm_area_struct 0x8048000 0x0000000
Time and Timers • Real SIGALRM • Virtual SIGVTALRM • Profile SIGPROF • 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; • unsigned long start_time ; • struct tms times ;
struct timer_list { struct timer_list * next ; struct timer_list * prev ; unsigned long expires ; unsigned long data ; void (* function) (unsigned long) ; } ; struct tms { clock_t tms_utime; clock_t tms_stime; clock_t tms_cutime; clock_t tms_cstime; };
Execute Programs • struct linux_binfmt * binfmt ; format
int exit_code, exit_signal ; • int dumpable:1 ; • int did_exec:1 ; • char comm [16] ; • struct rlimit rlim [RLIM_NLIMITS] ;
struct rlimit { long rlim_cur ; long rlim_max ; } ; #define RLIMIT_CPU 0 /* CPU time in ms */ #define RLIMIT_FSIZE 1 /* Maximum filesize */ #define RLIMIT_DATA 2 /* max data size */ #define RLIMIT_STACK 3 /* max stack size */ #define RLIMIT_CORE 4 /* max core file size */ #define RLIMIT_RSS 5 /* max resident set size */ #define RLIMIT_NPROC 6 /* max number of processes */ #define RLIMIT_NOFILE 7 /* max number of open files */ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIM_NLIMITS 10
sigset_t signal, blocked ; • struct signal_struct * sig ; • struct sem_undo * semundo ; • struct sem_queue * semsleeping ; • struct wait_queue * wait_chldexit ; • struct semaphore * vfork_sem ;
struct wait_queue { struct task_struct * task ; struct wait_queue * next ; } ; struct semaphore { atomic_t count ; int waking ; struct wait_queue * wait ; } ;