Chapter 5 Controlling Processes Xiaoli Jiao 6/8/99
What is a “Process”? --A program in execution --Only one process is actually executing at a time What Sys Administrator can do with processes? --Monitor the status of processes --Control CPU time a process can get --Send signals to a process --Suspend or halt process execution
Components of a process: Address space –segments of program code –variables –stack –extra information Internal Data structures –address space map –current status –execution priority –signal mask –owner
What we are interested? PID: Process Identification Number PPID: Parent Process ID UID & GID: Creator’s User ID and Group ID EUID & EGID: “ what resources can be accessed?” Priority and Nice Value: “how much CPU time to receive?” Control Terminal: the default linkages for standard I/O and error channels
Life Cycle of A Process when system boots, kernel creates several processes autonomously New processes are created by other processes. (like new humans!) All processes except those kernel creates are descendants of init, which always has PID 1.
Life Cycle of A Process-- Contd. An existing process clones itself using system call fork to create a new process. The new process use exec system calls to begin execution of a new program. When a process completes, it calls a routine named _exit to notify the kernel that it is ready to die. (--Zombie)
Process States StateMeaning RunnableThe process can be executed SleepingWaiting for some resources SwappedNot in memory ZombieTrying to die StoppedSuspended(not allowed to execute)
Signals Unix defines a set of signals for software and hardware conditions that may arise during the normal execution of a process. A process can specify an action for a signal, either: –catching the signal with a handler –or taking the default action Each signal has a default action that may be any one of –ignoring the signal –terminating the process(& generate a core dump) –stopping the process Signals KILL and STOP can not be caught, ignored or blocked
Kill : Send Signals Syntax : Kill [-signal] pid Kill -l displays the available kill signals umbc9[1]% kill -l HUP INT QUIT ILL TRAP ABRT EMT FPE KILL(9) BUS SEGV SYS PIPE ALRM TERM(15) USR1 USR2 CHLD PWR WINCH URG IO STOP TSTP CONT TTIN TTOU VTALRM PROF XCPU XFSZ Kill pid defaults to sending TERM(15) Kill -9 pid last resort -- “Nuke” without mercy
Priority and “nice value” Process with highest “internal priority” gets to run first “Nice Value” -- how the process should be treated in relationship to other processes contending CPU BSD: -19 ~ +19 ATT: 0 ~ 39 Lower value => Higher priority nice to set “nice value” at the process creation renice is used to change the value during process execution
Monitor Processes ps --Processes Status ( “snapshot”) –ps -aux (ATT) –ps -ef (BSD) top - display information about the top cpu processes A dynamically updated “big picture”
actaeon.cs.umbc.edu[112] ps -aux | grep Jun |more USER PID %CPU%MEM SZ RSS TT S START TIME COMMAND root console S Jun 03 0:00 /usr/lib/saf/ttymo root ? S Jun 04 0:00 in.telnetd root pts/18 S Jun 04 0:00 login -p -d /dev/p burt pts/18 S Jun 04 0:00 -csh burt pts/18 S Jun 04 0:00 script burt pts/18 S Jun 04 0:00 script burt pts/20 S Jun 04 0:00 sh -i burt pts/20 S Jun 04 0:00 tcsh burt pts/20 S Jun 04 0:00 /bin/csh jiao pts/11 S 10:05:34 0:00 grep Jun root ? S Jun 01 0:00 in.telnetd root pts/5 S Jun 01 0:00 login -p -d /dev/p root ? S Jun 02 0:00 in.rlogind root pts/32 S Jun 02 0:00 login -d /dev/pts/ ykatsn ? S Jun 01 0:00 /bin/sh /usr/local ykatsn ? S Jun 01 0:00 (dns helper) ykatsn ? S Jun 02 0:00 /bin/sh /usr/local ykatsn ? S Jun 02 0:00 (dns helper)
actaeon.cs.umbc.edu[114] top last pid: 10096; load averages: 1.01, 1.03, :19: processes: 115 sleeping, 1 running, 1 on cpu CPU states: 0.0% idle, 97.4% user, 2.6% kernel, 0.0% iowait, 0.0% swap Memory: 512M real, 66M free, 129M swap in use, 371M swap free renice PID USER THR PRI NICE SIZE RES STATE TIME CPU COMMAND 9521 ykatsn M 3432K run 138.0H 96.54% netscape 9551 ykatsn M 22M sleep 65: % netscape jiao K 1480K cpu 0: % top 9499 crowder K 3072K sleep 0: % pine 5263 root K 880K sleep 1: % rpc.nisd_resolv 5262 root K 1944K sleep 68: % ypserv 115 root K 1184K sleep 6: % rpcbind 266 root K 872K sleep 14: % sshd ykatsn M 16M sleep 1: % matlab 235 root K 440K sleep 1: % utmpd 256 root K 608K sleep 1: % xntpd 223 root K 2336K sleep 0: % nscd 3307 squiro K 1760K sleep 0: % windu_registryd 3411 squiro M 3880K sleep 0: % Medit 3706 squiro M 3880K sleep 0: % Medit
Special attentions NOHUP : Protect Background Process $ nohup command & Errant Processes For more information, please refer to Chapter 29.
Any Questions?