150 likes | 295 Views
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
E N D
UNIX System Administration HandbookChapter 4. Controlling Processes 3rd 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 forkto create a new process. • The new process use execsystem 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@localhost lsong1]$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 1.0 0.1 1372 480 ? S 10:33 0:04 init [3] root 2 0.0 0.0 0 0 ? SW 10:33 0:00 [keventd] root 3 0.0 0.0 0 0 ? SW 10:33 0:00 [kapmd] root 1032 0.0 0.1 1544 620 ? S 10:35 0:00 crond wnn 1052 0.0 0.6 3676 2440 ? S 10:35 0:00 /usr/bin/tserver xfs 1110 0.1 1.1 5704 4396 ? S 10:35 0:00 xfs -droppriv -da root 1128 0.0 0.1 1380 552 ? S 10:35 0:00 anacron daemon 1146 0.0 0.1 1404 524 ? S 10:35 0:00 /usr/sbin/atd root 1173 0.0 0.1 1344 400 tty2 S 10:35 0:00 /sbin/mingetty tt lsong1 1545 0.4 2.5 21192 9960 ? S 10:39 0:00 kdeinit: kwrited lsong1 1548 0.6 2.5 20488 9972 ? S 10:39 0:00 korgac --miniicon lsong1 1549 0.5 2.3 20260 8928 ? S 10:39 0:00 kalarmd -session lsong1 1551 0.0 1.9 19588 7484 ? S 10:39 0:00 kdeinit: kio_file lsong1 1552 0.0 0.1 1804 652 ? S 10:39 0:00 autorun -l --inte lsong1 1568 0.0 1.9 19588 7528 ? S 10:39 0:00 kdeinit: kio_file lsong1 1569 0.0 1.9 19600 7540 ? S 10:39 0:00 kdeinit: kio_file lsong1 1570 4.7 3.1 22916 12268 ? S 10:40 0:00 kdeinit: konsole lsong1 1572 0.7 0.3 2520 1344 pts/1 S 10:40 0:00 /bin/bash lsong1 1603 0.0 0.1 2676 756 pts/1 R 10:40 0:00 ps aux
10:53am up 19 min, 4 users, load average: 0.01, 0.25, 0.29 70 processes: 66 sleeping, 4 running, 0 zombie, 0 stopped CPU states: 7.6% user, 5.0% system, 0.0% nice, 87.2% idle Mem: 385112K av, 378144K used, 6968K free, 0K shrd, 22376K buff Swap: 506480K av, 0K used, 506480K free 162644K cached PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 10277 lsong1 15 0 1032 1032 828 R 1.9 0.2 0:00 top 1452 root 15 0 48196 20M 4680 R 0.9 5.4 0:09 X 1570 lsong1 15 0 15012 14M 12380 R 0.9 3.8 0:05 kdeinit 1 root 15 0 480 480 420 S 0.0 0.1 0:04 init 5 root 15 0 0 0 0 SW 0.0 0.0 0:00 kswapd 1400 root 15 0 1184 1184 960 S 0.0 0.3 0:00 login 1401 lsong1 15 0 1276 1276 1000 S 0.0 0.3 0:00 bash 1440 lsong1 16 0 1016 1016 868 S 0.0 0.2 0:00 startx 1451 lsong1 15 0 608 608 536 S 0.0 0.1 0:00 xinit 1456 lsong1 15 0 1052 1052 892 S 0.0 0.2 0:00 startkde 1911 root 15 0 9864 9864 8572 S 0.0 2.5 0:00 kppp 1912 root 15 0 5152 5148 4756 S 0.0 1.3 0:00 kppp 1914 root 16 0 6656 6652 6400 S 0.0 1.7 0:00 kdeinit 1917 root 18 0 7152 7148 6860 S 0.0 1.8 0:00 kdeinit 1920 root 18 0 7624 7620 7252 S 0.0 1.9 0:00 kdeinit 1922 root 15 0 9232 9228 8420 S 0.0 2.3 0:00 kdeinit 1928 root 15 0 832 832 692 S 0.0 0.2 0:00 pppd 1947 lsong1 15 0 25364 24M 9596 R 0.0 6.4 0:08 netscape-commun 2011 lsong1 15 0 3736 3660 3192 S 0.0 0.9 0:00 netscape-commun 10272 lsong1 15 0 7532 7528 7288 S 0.0 1.9 0: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--highpriority • 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-9pidguarantee 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