ps, kill, pkill, top, nohup
‣ ps provides a snapshot current processes
UNIX> ps
PID TTY TIME CMD
5184 pts/0 00:00:00 bash
5215 pts/0 00:00:00 ps
UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215 pts/0 00:00:00 ps
‣ PID: Process ID ‣ TTY: owning terminal ‣ TIME: process runtime ‣ CMD: command
‣ -A option for ALL processes
UNIX> ps –A
PID TTY TIME CMD
1 ? 00:00:01 init
…….
29541 ? 00:00:03 update-notifier
29915 ? 00:00:00 gtk-logout-help
‣ LOTS of processes running… – most control the OS (so don’t kill them)
UNIX> ps –A | wc –l 277 UNIX>ps -A | grep daemon | head –n 2 1729 ? 00:00:03 dbus-daemon 1742 ? 00:00:33 avahi-daemon
‣ -u option specifies the user
UNIX> ps –u qhan
PID TTY TIME CMD
5183 ? 00:00:00 sshd
5184 pts/0 00:00:00 bash
5261 pts/0 00:00:00 ps
UNIX> ps –u root | head –n 5
PID TTY TIME CMD
1 ? 00:00:01 init
2 ? 00:00:00 kthreadd
3 ? 00:00:00 migration/0
4 ? 00:00:00 ksoftirqd/0
‣ kill terminates one or more processes ‣ sends SIGTERM signal to process (default) ‣ Command line argument(s) specify PID(s) to kill
UNIX> ./runaway & [1] 5177
UNIX> kill 5177
UNIX> ./runaway & [1] 5282
UNIX> kill 5282
UNIX> ps | grep runaway [1]+ Terminated ./runaway
‣ -9 option is more “forceful” kill ‣ sends SIGKILL signal to process ‣ SIGKILL cannot be blocked!
UNIX> ./super_runaway & [1] 5455
UNIX> kill -9 5455
‣ pkill takes CMD instead of PID
UNIX> ./runaway & [1] 5350
UNIX> pkill runaway [1]+ Terminated ./runaway
‣ top displays real-time information about current tasks ‣ top is a very powerful command line tool ‣ by default, top refreshes every 3 seconds ‣ top displays CPU, cache, memory, swap space,
virtual memory, runtimes, commands, etc. UNIX> top ‘q’ to quit..
‣ See lecture notes for details:
‣ http://mcs.mines.edu/Courses/csci298/Content/process.html
‣ While top is running, hit ‘d’ to specify delay time between updates
‣ Default delay is 3 seconds
‣ Change delay time to 0.5 seconds:
(zoomed in screen shot)
‣ While top is running, hit ‘u’ to specify user
‣ Default is ALL users
‣ Change user to mrubin:
(zoomed in screen shots)
‣ -u command line option to specify user
‣ select user BEFORE top begins
UNIX> top –u mrubin
‣ nohup runs a command immune to hangups – process continues even after logging out!
‣ nohup does not output to a tty (terminal) – output appended to nohup.out
‣ very useful for running large jobs – e.g., a simulation that takes hours or days to run
‣ E.g., process that prints “HELLO THERE” to stdout every second
UNIX> ssh someMachine
UNIX> ./sleep_print.sh
HELLO THERE
HELLO THERE
<CTRL-C>
UNIX>
‣ run in background and without hangups (nohup)
UNIX> nohup ./sleep_print.sh &
[1] 5594
nohup: ignoring input and appending output to `nohup.out’
UNIX> wc –l nohup.out
4
UNIX> exit UNIX> ssh someMachine UNIX> ps -u qhan| grep sleep_print.sh 5594 ? 00:00:00 sleep_print.sh UNIX> pkill sleep_print.sh UNIX> wc –l nohup.out 25 nohup.out
‣ http://eecs.mines.edu/Courses/csci274/Assignments/11_processes.html
‣ Practice, practice, practice
init
do you get this?