Saturday, June 02, 2012

Linux 13 - Create, Monitor and Kill Processes

  • background and foreground
  • persistent processes
  • interact with processes
  • sort running processes in top
Background and Foreground
# sleep 1000
  • captures the terminal and sleeps for 1000 sec
    • to run in bacground add & to the end
      • this wil give back control of terminal
  • to access programs from background use jobs commands
  • typing fg <job number> will bring it into foreground
  • to put something in the background you can suspend the process by
    • CTRL+Z
    • jobs command will show it as suspended
    • to un-suspend the process but still keep it in the background
      • use command bg <job number>
  • If jobs are running in the background you can interact with them as long as the terminal windows is open
    • Once closed the only way to terminate a job is with
      • kill follwed by the PID
      • kill has two main ways to kill a process
        • kill -l 15 // TERM
        • kill -l 9  //  KILL
  • by default kill will use 15. 15 is a nice way to kill the prcoesses
  • by using 9 we risk having orphaned processes in the system

Persistent Processes
A process that still runs even after the user logs off

# nohup sleep 1000 &
[1] 3029
# nohup: ignoring input and appending output to `nohup.out'

nohup is meant to "run a program immune to hangups"

Interact with processes
top

- similar to task manager in windows
- by default it will sort by CPU usage

image
by pressing the h key (help) it will show us the different arguments it can have
image
by using the < and > keys we can sort by different catogries
image
to kill a process
by default Kill PID 3420 with signal [15]:
image
uptime
- presents system uptime, logged-in users, load average in 1, 5 and 15 minute intervals

# uptime
01:44:40 up 1:08, 2 users, load average: 0.00, 0.00, 0.00
average is in intervals of 1 minute, 5 minutes, 15 minutes

free
- presents free, used, total, cached, swap system memory

image

No comments:

Post a Comment