kill
ps
nice
renice
top
fuser
echo
This table summarizes the typical process environment consisting
of variables and parameters required to run.
| Terminal (TTY) | Terminal ID from which the process was launched, provies linkage for 3 file descriptors: stdin, stdout, stderr |
| Open files | Files the process is using |
| Current directory | The directory from which the process was invoked |
| User ID (UID) | ID of the user who invoked the process |
| Effective User ID (EUID) | Determines what resources and files a process has permission to access at any given moment. There is a distinction between identity and permission. Think of setuid programs like sudo. (Next chapter) |
| Group ID (GID) | ID of the group that the user belongs to |
| Process ID (PID) | A unique number that the kernel randomly assigned to the process |
| Parent process ID (PPID) | The parent process ID, which launched the subject process |
| Priority | The processes scheduling priority or niceness. Determines how much CPU the process receives |
Checking the Shell's Process ID (PID)
$ echo $$Parent-Child Relationships
3173
All processes exist in parent-child hierarchies.
$ ps -laxfw | less
(excerpt)
UID PID PPID PRI STAT TTY TIME COMMAND
500 5269
5095 15 S pts/6 0:01
\_ /bin/bash
500 18006 5269
17 R pts/6 0:00
\_ ps -laxfw
500 18007 5269
16 S pts/6 0:00
\_ less
Process Signals
| Numeric | bash name | Description |
| 1 | HUP | Hang-up signal 1. reset request for processes to reread config files (ie, syslog, init) 2. signal also generated by modem connection when dropped. |
| 2 | INT | Interrupt signal sent when <Ctrl-C> is typed at keyboard, terminate the current operation. Most programs simply allow themselves to be killed. Some processes may wait for more text input from keyboard. |
| 3 | QUIT | Similar to TERM, produces a core dump if not caught by process. |
| 9 | KILL | Unconditional kill -- not graceful, no cleanup. |
| 11 | SEGV | Segmentation fault caused by improper access of memory. |
| 15 | TERM | Termination signal which instructs process to terminate, graceful termination! |
Terminating Processes
Why would you want to terminate one of you beloved processes:
Foreground processes
kill PID1 PID2 PID3Note that the process IDs are separated by a space. You can have as many as you want listed after the kill command and optional signal.
kill [-signal] PID
killall [-signal] process_name
Example -- to create output and load:
[pattyo@ponto $ bash
[pattyo@ponto]$ yes > /dev/null &
[1] 6023What the heck is the yes command anyway?
$ man yes
NAME
yes - output a string repeatedly until killed
[pattyo@ponto]$ ps fNo error message is displayed. Check process exit status.
PID TTY STAT TIME COMMAND
763 pts/0 S 0:00 bash
6013 pts/0 S 0:00 bash
6023 pts/0 R 0:03 \_ yes
6024 pts/0 R 0:00 \_ ps f[pattyo@ponto]$ kill 6023
[pattyo@ponto]$
[pattyo@ponto]$ echo $?Using the killall command
0
[1]+ Terminated yes >/dev/nullA return code of 0 is good news, anything else for an exit status is bad.
$ sudo killall -15 xinetd
kill Command Signals
To get a complete listing of the kill signals type:
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGIOT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO
30) SIGPWR 31) SIGSYS
The ps (process status) command is used to
$ psOutput of ps Command above
PID TTY TIME CMD
889 pts/3 00:00:00 bash
5708 pts/3 00:00:00 ps
| PID | Process identification number assigned by the kernel |
| TTY | Terminal where the process originated |
| TIME | Cumulative execution time (min:sec) |
| COMMAND | Name of the process being executed |
ps options (documented
in man pages)
| u | select by user name |
| a | Select all processes on a terminal-- including those of other users |
| x | Select processes without controlling ttys |
| f | ASCII-art process heirarchy (forest) |
| e | Environment of the process |
| l | Long listing (along with basic flags) |
The top command
Provides a way to view the
most CPU intensive processes at any given moment
PID USER PRI NI SIZE
RSS SHARE STAT %CPU %MEM TIME COMMAND
1960 root 16 0 15760
11M 2536 R 4.5 7.2 0:09 X
2154 pattyo 11 0 15396 14M
8964 S 2.3 9.5 0:05 netscape-commun
2189 pattyo 14 0 1064 1064
836 R 0.9 0.6 0:00 top
1995 pattyo 12 0 3728 3728
2048 S 0.7 2.3 0:03 sawfish
2019 pattyo 9 0 5384
5384 3980 S 0.3 3.3 0:01
panel
2 root 9
0 0 0 0
SW 0.1 0.0 0:00 keventd
1977 pattyo 9 0 2044
2044 1704 S 0.1 1.2 0:00
gnome-smproxy
2021 pattyo 9 0 4328
4328 3480 S 0.1 2.7 0:00
gnome-terminal
2122 pattyo 9 0 3876
3876 3240 S 0.1 2.4 0:00
deskguide_apple
1 root 8
0 520 520 452 S 0.0
0.3 0:04 init
3 root 9
0 0 0 0
SW 0.0 0.0 0:00 kapm-idled
4 root 19 19
0 0 0 SWN 0.0
0.0 0:00 ksoftirqd_CPU0
5 root 9
0 0 0 0
SW 0.0 0.0 0:00 kswapd
6 root 9
0 0 0 0
SW 0.0 0.0 0:00 kreclaimd
7 root 9
0 0 0 0
SW 0.0 0.0 0:00 bdflush
8 root 9
0 0 0 0
SW 0.0 0.0 0:00 kupdated
9 root -1 -20
0 0 0 SW< 0.0
0.0 0:00 mdrecoveryd
GUI tools provided on your Linux system
gtop
Memory Usage
$ sudo kill `ps -lax | grep nfsd | \Renicing a process
grep -v grep | awk '{print $3}'`
Use ps -lax to view fields such as the parent process IDs and nice values of your processes.
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
000 500 8529 8527 15 0 2556 1236 wait4 S pts/1 0:01 /bin/bash
$ renice -1 8529
renice: 8529: setpriority: Permission
denied
$ renice 16 8529
8529: old priority 15, new priority
16
$ renice 15 8529
renice: 8529: setpriority: Permission
denied
$ sudo renice 15 8529
Password:
8529: old priority 16, new priority
15
$ sudo nice --adjustment=-10 bashThis command creates a shell with a nice value of 10 less than the default.
$ ps -lax | tail
while [ 1 ]; do
cal 2000 > /dev/null
done
# fuser -mv /home
{identify
processes using files}
# lsof /home
{list
open files}
| State | Meaning |
| Runnable | The process can be exectued whenever the cpu is ready |
| Sleeping | The process is waiting for some resource, or keyboard input |
| Zombie | The process is finished but has not reported its status back to its parent |
| Stopped | The process is suspended, received a STOP signal |
Sometimes a child process is killed (with a -9 signal) but the parent doesn't acknowledge the termination.
$ ps -ef | egrep 'd$|d]$'
...
root 333 1 0 Oct16
? 00:00:00 rpc.statd
root 395
1 0 Oct16 ? 00:00:34 klogd
root 423
1 0 Oct16 ? 00:00:01 crond
root 437
1 0 Oct16 ? 00:00:00 inetd
named 451
1 0 Oct16 ? 00:00:01 named
root 460
1 0 Oct16 ? 00:00:00 sshd
root 476
1 0 Oct16 ? 00:00:00 lpd
...
Notice the parent process for most daemons is init.
command options argumentsBackground Process
command options arguments > backfile &Here you are saving the output to the file backfile. Note the ampersand at the end of the command. This is how a background process is invoked.
Job Control in the bash and tcsh Shells
jobs
$ nohup yes >> junk 2>&1 &Suspending and Resuming a Foreground Task
[1] 6292
$ jobs
[1]+ Running nohup yes >>junk 2>&1 &
$ ps
PID TTY TIME CMD
776 pts/1 00:00:00 bash
6292 pts/1 00:00:11 yes
6295 pts/1 00:00:00 ps
$ kill -15 6292
$ jobs
[1]+ Terminated nohup yes >>junk 2>&1Note: kill -15 is using the TERM signal for graceful termination.
To suspend a foreground task:
$ yes > /dev/nullTo resume a suspended task:
<Ctrl-z>
[1]+ Stopped
[pattyo@ponto fall2001]$ fgTo suspend a background task you will first need to bring it to the foreground using the fg command. Then suspend it using <Ctrl>-z>.
yes >/dev/null
If you have have more than one process running in the background you will need to provide a jobnumber to the fg command.
Example:
$ yes > /dev/null
<Ctrl>z
[1]+ Stopped yes >/dev/null$ yes > /dev/null &
[2] 6440$ jobs
[1]+ Stopped yes >/dev/null
[2]- Running yes >/dev/null &Now we have two jobs, one stopped, one running
$ fg %2
yes >/dev/null
<Ctrl>z
[2]+ Stopped yes >/dev/null$ jobs
[1]- Stopped yes >/dev/null
[2]+ Stopped yes >/dev/null