Thursday, January 21, 2016

Processes:::
parent process
child process
different process states::
R = task running
S = sleeping
D = sleeping (but interruptible)
K =task killable
T = task stopped
Z=exit zombie(a child process signals as its parents exits
.all resources except for the process identity (PID) are realeased
X= exit dead

listing processes:: ps -aux ( displays all processes with columns in which users will be
interested)

[ashok@localhost ~]$ ps -aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.3  0.3 126588  7384 ?        Ss   09:46   0:04 /usr/lib/syste
root          2  0.0  0.0      0     0 ?        S    09:46   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    09:46   0:00 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   09:46   0:00 [kworker/0:0H]
root          6  0.0  0.0      0     0 ?        S    09:46   0:00 [kworker/u256:
root          7  0.0  0.0      0     0 ?        S    09:46   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    09:46   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/0]
root         10  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/1]
root         11  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/2]
root         12  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/3]
root         13  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/4]

 ps -lax gives more technical detail and more faster coz it doesnt
provide username( ps -ef is also a unix command to look all processes)

[ashok@localhost ~]$ ps -lax
F   UID    PID   PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0      1      0  20   0 126588  7384 ep_pol Ss   ?          0:04 /usr/lib/
1     0      2      0  20   0      0     0 kthrea S    ?          0:00 [kthreadd
1     0      3      2  20   0      0     0 smpboo S    ?          0:00 [ksoftirq
1     0      6      2  20   0      0     0 worker S    ?


       0:00 [kwo


Controlling jobs::
 running jobs in the background::

[ashok@localhost ~]$ sleep 1000 &
[1] 4998
 checking if jobs is running:
[ashok@localhost ~]$ jobs
[1]+  Running                 sleep 1000 &

bringing job in the foreground:;
[ashok@localhost ~]$ fg %1
sleep 1000

To again send the job to background and send the suspend request
press Ctrl-z
[ashok@localhost ~]$ fg %1
sleep 1000
^Z
[1]+  Stopped                 sleep 1000

ps with option j displays job information including the command shell of each session
ashok@localhost ~]$ ps j
  PPID    PID   PGID    SID TTY       TPGID STAT   UID   TIME COMMAND
  4146   4150   4150   4150 pts/0      4150 Ss+   1000   0:00 /bin/bash
  4272   4274   4274   4274 pts/1      5174 Ss    1000   0:00 -bash
  4274   5165   5165   4274 pts/1      5174 T     1000   0:00 sleep 1000
  4274   5174   5174   4274 pts/1      5174 R+    1000   0:00ps j

 Killing processes::
 to list signals

[ashok@localhost ~]$ kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   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      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

 we can use killall to send signal for more processes at once under
certain pattern.
even pkill is used to send signal to multiple processes at once
 pkill command_pattern
pkill -signal command_pattern
pkill -G GID command_pattern
pkill -t terminal_name -U UID command_pattern


pgrep -l -u username searches for all the processes associated with that username

[root@localhost ~]# pgrep -l -u ashok
3280 gnome-keyring-d
3323 gnome-session
3330 dbus-launch
3331 dbus-daemon
3396 gvfsd
3400 gvfsd-fuse
3475 ssh-agent
3491 at-spi-bus-laun
3495 dbus-daemon
3500 at-spi2-registr
3511 gnome-settin


To see all the process tree for the system or single user, we use pstree command
[root@localhost ~]# pstree -p ashok

at-spi-bus-laun(3491)─┬─dbus-daemon(3495)───{dbus-daemon}(3497)
                      ├─{at-spi-bus-laun}(3492)
                      ├─{at-spi-bus-laun}(3494)
                      └─{at-spi-bus-laun}(3496)
pkill -p 3491 will kill all the children they have created because
here the PPID is 3491 and parent is at-spi-bus-laun(3491)


No comments:

Post a Comment