Basic process monitoring and control
ps # list processes.
With no arguments, lists processes running in current shell.
Lists :
- process ID
- terminal running on
- CPU time used
- command name
Options :
-u user-id # list any processes named user owns on system.
-e # lists every process running.
-f # full, often uses with -e, lists additional information
- UID - owner
- PID - process ID
- PPID - parent process ID, what started current processes.
- C - ?
- STIME - start time of process (approx)
- TTY - terminal launched from, ? means a non-terminal related service.
- TIME - CPU time used
- CMD - command name
- # additional options provide selection of sub-set of all processes.
ps also supports Berkeley style options which use different option
syntax and generate slightly different output.
pstree [user-id] - display process chain in a tree pattern.
Some Options :
-a # show options used with processes.
-p # show process IDs in parens.
# number of options to modify output format.
With no user ID, lists all process, may be too large to be useful.
Some options only work on user's own processes, unless user is admin.
top - list top processes by CPU usage.
- Lists general system resource usage.
- Lists top 'performing' processes, updated every 5 seconds.
- Process list expands to use whole screen.
- Use q to kill display.
Some Options :
-d ss.t # set update frequency.
-n d # update screen d times then quit.
-p dddd # monitor only process of given ID.
-u user-id # monitor only processes of given user ID
Keystroke process control
^c # [ctrl]c - interrupt a process.
- Equivalent of kill -1 or kill -HUP
- Signals interrupt of process.
- Process may respond, ignore, or take modified action.
^d # [ctrl]d - end of file.
- Represents end of input.
- Use export IGNOREEOF=10 to prevent logging out.
; # semi-colon - allows user to specify multiple commands on cmd line.
- Each command completes before next command is started.
& # ampersand - allows user to specify multiple commands on cmd line.
Placed at the end of a command.
Starts command as a background process.
Next command starts without previous command completing.
If command requires standard input, it will stop until user attends to it.
^z # [ctrl]z - suspends current foreground process (stopped).
Use fg or bg to restart process.
jobs # lists background jobs or processes in current shell.
Lists both running and stopped jobs.
Numbered sequentially from one or from current background job.
Options
jobs -l
- long listing.
- includes both job and process ID and possible reason for stopped state.
bg # background - starts a suspended background process.
bg
bg %1
bg is an internal shell command.
Applies only to jobs in current shell.
Issued without an argument, works last job accessed.
Use with %n, where n is job ID of target process.
If job requires input from command line, it will stop until user brings it
into the foreground.
fg # foreground - brings a background process to the foreground.
fg
fg %1
fg is an internal shell command.
Applies only to jobs in current shell.
Issued without an argument, targets last job accessed.
Use with %n, where n is job ID of target process.
kill PID # signal process change to targeted process.
Most common used to generate a terminate (kill) signal.
Available both as a bash function and as a stand alone program.
User can only signal (kill) own processes.
Options and features vary between versions.
Many signals can be trapped by process.
Some signals are untrappable. e.g kill -9 PID
Some Options :
# no signal choice, default is SIGTERM (15).
-l # (bash) list available signals and their numeric values
-L # (system) list available signals and their numeric values
-n | -s n | --signal n # specify numeric signal value to send
-sig-name # use signal name specified by the list option
/bin/kill [-n] PID # (system) send signal to ID'ed process.
kill [-n] {PID|Job-ID} # (bash) send signal to ID'ed process.
The bash kill may use either process ID or job ID as long as job in same
shell.
pgrep program # lists PID of processes matching program name.
options to further refine match.
will identify all matches even if owned by others.
pkill program # finds processes matching program name and kills
them.
options to further refine match.
options to specify signal to send.
will only be applied to processes owned by issuer> # use regular expression to describe process to target.
killall cmd-name # kills set of related processes in single
action.
cmd-name name of process being targeted.
Only usable on processes you own.
Some Options :
-n | -s n | -SIGNAME # designate signal to send.
-r reg-ex # use regular expression to describe process to target.
-I cmd-name # ignore case of process name.
-i cmd-name # prompt user before signaling each process matched.
-u user-id # target processes belonging to name user. More useful for
admin that standard user.
Our systems are set to a user to run only 50 processes. If a process attempts
to spawn more than this it will be blocked.
However, because the command interpreter is also a process, you may find that
once you hit this limit, you may not be able to stop the run-away process on
your own. Please contact your professor or the sysadmin for help.