UNIX System Administration Handbook Chapter 4. Controlling Processes 3 rd Edition Evi Nemeth et al. Li Song CMSC691X Summer 2002
Process A running program Manage and monitor a program’s use of memory, processor time, and I/O resources
Components of a Process Address space segments of program code variables stack extra information Internal data structure address space map current status execution priority signal mask owner
Parameters PID: process ID number PPID: parent PID UID/EUID: real and effective user ID GID/EGID: real and effective group ID Niceness Control terminal
Life Cycle of a Process When system boots, kernel creates several processes autonomously, e.g. init, which always has PID 1. All processes except those kernel creates are descendants of init.
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. Parent process calls wait to receive a copy of the child’s exit code. init is supposed to accept orphaned processes and perform the wait.
Process States Runnable: the process can be executed Sleeping: waiting for some resources Zombie: trying to die Stopped: suspended(not allowed to execute
PS: Monitor Process ps : processes status --“snapshot” ps aux, ps lax - Red Hat and FreeBSD ps ef, ps elf – Solaris and HP-UX top : display information about the top CPU processes, update every 10 sec -- a dynamically updated “big picture”
lsong1]$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root ? S 10:33 0:04 init [3] root ? SW 10:33 0:00 [keventd] root ? SW 10:33 0:00 [kapmd] root ? S 10:35 0:00 crond wnn ? S 10:35 0:00 /usr/bin/tserver xfs ? S 10:35 0:00 xfs -droppriv -da root ? S 10:35 0:00 anacron daemon ? S 10:35 0:00 /usr/sbin/atd root tty2 S 10:35 0:00 /sbin/mingetty tt lsong ? S 10:39 0:00 kdeinit: kwrited lsong ? S 10:39 0:00 korgac --miniicon lsong ? S 10:39 0:00 kalarmd -session lsong ? S 10:39 0:00 kdeinit: kio_file lsong ? S 10:39 0:00 autorun -l --inte lsong ? S 10:39 0:00 kdeinit: kio_file lsong ? S 10:39 0:00 kdeinit: kio_file lsong ? S 10:40 0:00 kdeinit: konsole lsong pts/1 S 10:40 0:00 /bin/bash lsong pts/1 R 10:40 0:00 ps aux
10:53am up 19 min, 4 users, load average: 0.01, 0.25, processes: 66 sleeping, 4 running, 0 zombie, 0 stopped CPU states: 7.6% user, 5.0% system, 0.0% nice, 87.2% idle Mem: K av, K used, 6968K free, 0K shrd, 22376K buff Swap: K av, 0K used, K free K cached PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND lsong R :00 top 1452 root M 4680 R :09 X 1570 lsong M R :05 kdeinit 1 root S :04 init 5 root SW :00 kswapd 1400 root S :00 login 1401 lsong S :00 bash 1440 lsong S :00 startx 1451 lsong S :00 xinit 1456 lsong S :00 startkde 1911 root S :00 kppp 1912 root S :00 kppp 1914 root S :00 kdeinit 1917 root S :00 kdeinit 1920 root S :00 kdeinit 1922 root S :00 kdeinit 1928 root S :00 pppd 1947 lsong M 9596 R :08 netscape-commun 2011 lsong S :00 netscape-commun lsong S :00 kdeinit
Nice and Renice A numeric hint about how the process should be treated in relationship to other processes. High nice value--low priority Low/negative nice value--high priority nice : set “nice value” at the process creation. renice : change the value during process execution. Child process inherits the nice value of its parent. Owner of the process can only increase its nice value but cannot lower it.
Signals Process-level interrupt requests. When a signal is received: Handler is called if designated— ”catching” signal Default action by kernel: i.e. terminate, generate a core dump Program can ignore and block signals.
Signals—contd. Signals should know: HUP, INT, QUIT, KILL, TERM, STOP, TSTP, CONT… KILL and STOP cannot be caught, blocked, or ignored.
KILL: Send Signals Syntax : Kill [-signal] pid Signal is the number of the signal to be sent e.g. KILL (9), TERM(15) Kill pid defaults to sending TERM(15) Kill -9 pid guarantee the process will die
Runaway Processes User processes use up excessive amounts of a system resource (CPU time, disk space) System processes that suddenly exhibit wild behavior Looking at ps output Legitimate-renice to lower priority Destructive-STOP