http://www.technicalpage.net/search/label/SQL

>> ps command


"ps" command

ps - process status is used to see the status of running processes.
when noting is running and we enter "ps" then it displays :
  PID   TTY          TIME CMD
 4443  pts/1     00:00:00 bash
 4551  pts/1     00:00:00 ps

Where ,
PID :  is process ID
TTY :  is the name of the console or terminal into which the user is logged .
TIME  :  TIme in minute and seconds the process is being running in the CPU.
CMD is the name of the command that initiated the process .


Let's run below jobs and check with "ps" :
Job1:
sleep   100 &   click ENTER , it displays below information :
[1] 7642    ---- These are job number[1] and process ID (PID-7642)

job2:
sleep   105 &    click ENTER
[2] 7643

Check the status of the jobs by ENTERING the command "jobs" :

job  click ENTER
[1]-  Running                 sleep 100 &
[2]+  Running                 sleep 105 &

Now let's  check process status with the command  "ps" :
ps   click ENTER.

OutPut:
  PID TTY          TIME CMD
 4443 pts/1    00:00:00 bash
 7642 pts/1    00:00:00 sleep    --- first sleep command
 7643 pts/1    00:00:00 sleep    --- second sleep command
 7657 pts/1    00:00:00 ps

To see all the running/active process :  ps  -e  or ps -A

ps -e   click ENTER

Output :
  PID TTY          TIME CMD
    1 ?        00:00:03 init
    2 ?        00:00:00 migration/0
    .
    .
 3153 ?        00:00:00 hcid
 3159 ?        00:00:00 sdpd
 3181 ?        00:00:00 krfcommd
 3219 ?        00:00:02 pcscd
   .
   .
 4440 ?        00:00:04 gnome-terminal
 4442 ?        00:00:00 gnome-pty-helpe
 4443 pts/1    00:00:00 bash
 7642 pts/1    00:00:00 sleep
 7643 pts/1    00:00:00 sleep
 7658 pts/1    00:00:00 ps

To see the full list of all running processes : ps -ef

ps  -ef    click ENTER

OutPut:
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Mar09 ?        00:00:03 init [5]                      
root         2     1  0 Mar09 ?        00:00:00 [migration/0]
68             3     1  0 Mar09 ?        00:00:00 [ksoftirqd/0]
.
.
xfs        4437     1  0 Mar09 ?        00:00:00 gnome-screensaver
ram      4440     1  0 Mar09 ?        00:00:04 gnome-terminal
ram      4442  4440  0 Mar09 ?        00:00:00 gnome-pty-helper
ram      4443  4440  0 Mar09 pts/1    00:00:00 bash
ram      7642  4443  0 00:26 pts/1    00:00:00 sleep 100
ram      7643  4443  0 00:26 pts/1    00:00:00 sleep 105
ram      7659  4443  0 00:26 pts/1    00:00:00 ps -ef

To search the process with a filter , you can use any filter from :
UID     ,   PID , PPID , C ,STIME TTY     TIME CMD

such as :
ps  -ef | grep   ram
ps  -ef | grep   4440
ps  -ef | grep   screensaver
ps  -ef | grep   00:00:04



Kill Process/Job
you can kill a running process/job  by using "kill" command alongwith its  PID :

Let's  run   sleep   1000&  and then kill it :
sleep  1000&    click ENTER , after you click ENTER you get below information :
[1]    9019     where [1]  is the job number and 9019 is the process ID - PID

You can also get the PID using :  ps    or     ps  -e    or    ps  -ef

such as ,
if you click "ps" , you get below informaiton  :
  PID   TTY          TIME CMD
 4443 pts/1      00:00:00 bash
 9019 pts/1      00:00:00 sleep   ---- this the job/process which we need to kill.
 9048 pts/1      00:00:00 ps

" kill "   or  " kill  -9 "

Syntax :
kill  PID   click ENTER
kill  9019    click ENTER
now check the status of the job  sleep   1000&  by  using :  jobs    or     ps    or     ps  -e    or    ps  -ef

if you check the status with the command : "jobs',
it will show  " Terminated  " :
[1]+  Terminated              sleep 1000

if you check with the command "ps",
it will not show the job/process  like below :

  PID TTY          TIME CMD
 4443 pts/1    00:00:00 bash
 9218 pts/1    00:00:00 ps


In many situations , the job will not be terminated/killed  with only "kill" command. In such situation use "-9"  with "kill".

kill  -9   PID    click ENTER  --- this is killing the job/process forcefully.
kill  -9   9019   click ENTER

Now, if you check the status with the command job, it shows  "killed" :
[1]+  Killed                  sleep 1000

if you check with the command "ps",
it will not show the job/process  like  below :

  PID TTY          TIME CMD
 4443 pts/1    00:00:00 bash
 9218 pts/1    00:00:00 ps

No comments:

Post a Comment