There are two tools used to find info about running processes: ps and top
ps is a tool found on most if not all flavours of UNIX. Its syntax varies a lot, and for the sake of clearness I will speak only about the GNU-ps' syntax.
At the shell prompt, type
ps |
PID TTY TIME CMD 10923 pts/3 00:00:00 bash 12494 pts/3 00:00:00 ps |
To see all your processes, type
ps xu |
To see all processes, including those belonging to others type
ps axu |
Note: some older versions of ps use the
ps -axu |
See the ps manpage of the column headers of ps' output to find which column refers to what field.
Tip: use ps and grep together to find a specific process:
ps axu | grep my_process_name |
"top" is a nice useful tool that acts like ps but with an auto-refresh.
just type
top |
Common interactive options are:
p: sort by CPU usage (default)
m: sort by memory usage
s: adjust time between refreshes.
q: quit
"top" displays first general info about your system, such as uptime, number of users ,etc.
Then it reports global CPU and memory usage
Then come the list of running processes. Interesting fields are:
PID: PID of the process
user: owner of the process
PRI: priority, note that top's priority floats around 19
SIZE: size of the process, RSS is the size of the physical memory allocate, SHARE being the size of shared memory
STAT: state of the process: R for running, S for sleeping, Z for zombies.
In Unix the owner of a process (or the superuser) can send a signal to a process he owns (any process for the SU).
Some of these signals can be recognized by processes which can act accordingly.
Example: say you have a laptop, and a battey-monitoring tool. If the battery runs low, your monitoring program can send signals (SIGPWR, I guess) to your running programs so that they shut down correctly and then poweroff the computer.
SIGKILL (IMPORTANT): kills a process using deadly force. The process doesn't stand a chance of survival, and exits without performing any action, such as save-and-exit. USE CAUTION !
SIGTERM (IMPORTANT): asks strongly to a program to nicely stop. Most evolved programs "trap this signal" , and run some save-and-exit code. It might not work if the program is stone-dead, since it won't execute any code at all.
SIGINT: it's one you already know about ! That's what Ctrl-c sends. It's a nice way of saying goodbye to a process.
SIGQUIT: you already know this one also, it's usually what Ctrl-d sends when typed in a terminal.
SIGSTOP et SIGCONT: to temporarily halt a process or to ask it to continue. (Ctrl-z sends SIGSTOP whereas fg and bg send SIGCONT).
It is simple. You must know the PID of a process and then:
kill -signal_number PID |
kill -9 123 |
kill -SIGKILL 123 |
You can find the conversion table between signals' names and numbers by doing
kill -l |
If you want to run a process without hogging 99% of the CPU and upset other users, nice is for you. |
A process is usually run with the priority of its parent. To know your shell's priority type:
nice |
To run a niced command type:
nice my_command |
To specify the nice-level (relative to current shell's priority):
nice -n 14 |
To renice a job's priority, use renice.
renice +5 my_pid |
You can also specify "all the processes of a user":
renice +20 -u patient_guy |