20220321 164301
Process Management
ps - report a snapshot of the current processes.
every process has a pid (process ID)
some time- a process creates a child process
-that child process create other child process under itself
a process may have multiple child process
ex. process name p1 - pid101
child process c1 pid102 ppid101
c2 pid103 ppid101
to kill or termiate the process kill all childs first and parent
-----------------------------------
ps -e
ps -ef
ps -aux
ps -oe user,pid,ni,cmd
To see every process on the system using standard syntax:
ps -e
ps -ef
ps -eF
ps -ely
To see every process on the system using BSD syntax:
ps ax
ps axu
To print a process tree:
ps -ejH
ps axjf
To get info about threads:
ps -eLf
ps axms
To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM
To see every process running as root (real & effective ID) in user format:
ps -U root -u root u
To see every process with a user-defined format:
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -Ao pid,tt,user,fname,tmout,f,wchan
Print only the process IDs of syslogd:
ps -C syslogd -o pid=
Print only the name of PID 42:
ps -q 42 -o comm=
-----------------------------------------------
ps -e
PID TTY TIME CMD
1 ? 00:00:07 systemd
2 ? 00:00:00 kthreadd
ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 10:31 ? 00:00:07 /usr/lib/systemd/systemd --switche
root 2 0 0 10:31 ? 00:00:00 [kthreadd]
ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 128416 7056 ? Ss 10:31 0:07 /usr/lib/systemd/s
root 2 0.0 0.0 0 0 ? S 10:31 0:00 [kthreadd]
ps -oe user,pid,ni,cmd
-------------------------------------------
ps -eo user,pid,ni,cmd | grep 'firefox$'
student+ 14485 0 /usr/lib64/firefox/firefox
kill 14485 --kill process
how to check process and process id?
ps -e
ps -ef
ps -aux
ps -eo pid,cmd
how to kill the process?
kill pid
---------------------------------------
kill -l
1) SIGHUP 9) SIGKILL 15) SIGTERM 20) SIGTSTP
kill -15 pid is same as kill pid -- termiate the process
kill -9 pid -- kill process
sleep 100 &
[2] 16382
ps -eo pid,cmd | grep sleep
16350 sleep 60
16382 sleep 100
16406 grep --color=auto sleep
kill 16382
[2]- Terminated sleep 100
ps -eo pid,cmd | grep sleep
16428 sleep 60
16449 grep --color=auto sleep
sleep 100 &
[2] 16462
ps -eo pid,cmd | grep sleep
16428 sleep 60
16462 sleep 100
16472 grep --color=auto sleep
kill -15 16462
[2]- Terminated sleep 100
ps -eo pid,cmd | grep sleep
16428 sleep 60
16502 grep --color=auto sleep
sleep 100 &
[2] 16513
ps -eo pid,cmd | grep sleep
16428 sleep 60
16513 sleep 100
16523 grep --color=auto sleep
kill -9 16513
[2]- Killed sleep 100
ps -eo pid,cmd | grep sleep
16543 sleep 60
16558 grep --color=auto sleep
sleep 100 &
[2] 16572
ps -eo pid,cmd | grep sleep
16543 sleep 60
16572 sleep 100
16583 grep --color=auto sleep
kill -20 16572
[2]+ Stopped sleep 100
ps -eo pid,cmd | grep sleep
16543 sleep 60
16572 sleep 100
16606 grep --color=auto sleep
ps -eo pid,stat,cmd | grep sleep
16543 S sleep 60
16572 T sleep 100
16625 S+ grep --color=auto sleep
kill -1 16572
ps -eo pid,stat,cmd | grep sleep
16572 T sleep 100
16650 S sleep 60
16685 S+ grep --color=auto sleep
ps -eo pid,stat,cmd | grep sleep
16572 T sleep 100
16650 S sleep 60
16703 R+ grep --color=auto sleep
------------------------------------------