Process management Flashcards
List processes
ps -aux/ ps -ef[H] hierarchy
ps -u- list user processes
first process will get id=1
List processes with their state
ps -el states: S -sleep T- terminated (ctrl+z) X- dead (should not be seen) Z- zombie I -idle R -running
Set priority of processes
nice [from -20 to 19]
nice -n 10 ping google.com
(The higher the number the higher the priority)
Alter priority of running process
renice -n -15 2345 [PID]
Display processes in real time
top keys: k-kill process r-renice process Sorting: M- %MEM N- PID P- %CPU T- TIME+
Look for process based on name
pgrep -a ssh- lists pids and service paths
pgrep httpd only lists pids related to httpd
pgrep -u- list pids of current user
Check how long takes a process to run
time ping -n 10 google.com
Kill a process based on name
pkill ping
pkill -x httpd -to kill processes match exactly to httpd
List open files
lsof
Location in pseudo FS related to cpu and memory
cat /proc/cpuinfo
cat /proc/meminfo
Tell how long the system has been running
uptime (1m, 5m, 15 m)
Report system activity info
sar -u for CPU utilization
sar -A -report for all devices
sar -b -IO stat
sar -d -for each block device
Configure kernel params in runtime
sysctl -a (display all values available)
Kill process
kill -9 1234 [pid]
kill 1234
kill -l- get the list of signal to be passed to kill command
Amount of RAM available+swap
free -m
Kill all processes based on name
killall httpd
killall -s 9 httpd
Run a command at specified intervals
watch date
watch -n 10 date
Terminal window managers that allows to run commands in an isolated session
- screen
1.1. screen
1.2. watch date
1.3. ctlr+a d -detach from the session
1.4. screen -r 2 [session screen id] -to re-attach
screen -ls -to show screen session - tmux
2.1. ssh kenny@1.2.3.4 …
run commands
2.2. ctrl+b d-detach from tmux session
2.3. tmux ls - list sessions
2.4 tmux attach-session -t 0-
attach back to the session 0
nohup
- nohup ping google.com &
- jobs -to see processes running on the background
- tail -f nohup.out
- fg 1 (job id) - back the job to fg
- ctrl+z - to stop the job
- bg % 1 (job id)-force to send the job to the background again
- jobs -l => the nohup ping google.com is running again