21
ps, kill, pkill, top, nohup

ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

Embed Size (px)

Citation preview

Page 1: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

ps, kill, pkill, top, nohup

Page 2: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ 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

Page 3: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

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

Page 4: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣  -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

Page 5: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ 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

Page 6: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ -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

Page 7: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

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

Page 8: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣  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

Page 9: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

UNIX> ./runaway & [1] 5282

UNIX> kill 5282

UNIX> ps | grep runaway [1]+ Terminated ./runaway

Page 10: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣  -9 option is more “forceful” kill ‣  sends SIGKILL signal to process ‣  SIGKILL cannot be blocked!

UNIX> ./super_runaway & [1] 5455

UNIX> kill -9 5455

Page 11: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ pkill takes CMD instead of PID

UNIX> ./runaway & [1] 5350

UNIX> pkill runaway [1]+ Terminated ./runaway

Page 12: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣  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..

Page 13: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ See lecture notes for details:

‣ http://mcs.mines.edu/Courses/csci298/Content/process.html

Page 14: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ 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)  

Page 15: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ While top is running, hit ‘u’ to specify user

‣ Default is ALL users

‣ Change user to mrubin:

(zoomed  in  screen  shots)  

Page 16: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ -u command line option to specify user

‣  select user BEFORE top begins

UNIX> top –u mrubin

Page 17: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ 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

Page 18: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣  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>

Page 19: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣  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

Page 20: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

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

Page 21: ps, kill, pkill, top, nohup - Oregon State Universityweb.engr.oregonstate.edu/~rubinma/Mines_274/Content/.../11_process… · UNIX> ps PID TTY TIME CMD 5184 pts/0 00:00:00 bash 5215

‣ http://eecs.mines.edu/Courses/csci274/Assignments/11_processes.html

‣ Practice, practice, practice

init  

do  you  get  this?