Commands - Processes
Processes
Updated at 2018-06-28 23:19
This note is about controlling running processes on Unix machines. These work on most distributions, but sometimes you need to install the program.
Linux processes are in a tree where PID 1 is init or systemd in more recent systems.
ps
# Show running processes.
# -u show process owner
# -a show processes from other users
# -x show processes not running inside a terminal
# -l show parent process id
-19 to 20
nice -n 19 top
renice -n 10 2345
kill -l
Currently Running Processes
ps aux
# ps = show your own processes
# a = all processes of all users
# u = show the user that owns the process
# x = list processes without terminal (tty)
# Tell process start time
ps -eo pid,lstart,command
# Find in processes.
ps ax | grep <PROCESS_NAME>
# LiSt Open Files, what files processes are using.
lsof
Process Monitor
# Table Of Processes, Shows what processes take most CPU etc.
top
# Accumulative, count events and such since launch of top.
top -a
Timing
time sleep 5
Stopping Processes
# Most of the time, you can stop the process you are currently
# executing with Ctrl+C. If not, open another terminal and kill it.
# Nice stop.
nice <PROCESS_NAME>
# Forceful stop.
kill <PROCESS_ID>
pkill <PROCESS_NAME>
Background Processes
To move a process to the background, end the command with &
sleep 10 &
sleep 10 &
jobs
# [1]- Running sleep 2000 &
# [2]+ Running sleep 2000 &
# Note that programs in the background are still children of the terminal.
# If the terminal process dies, they will die too.
# But you can detach them with nohup
nohup sleep 10 &
nohup sleep 10 &
nohup sleep 10 &
jobs