procps tool on Linux for process

procps is very useful package, specially if you want to check the jobs, load or any system process information.

Some of the useful tools available on procps are as below:

Find out the load average:     uptime:

-> uptime
10:46 up 6 days, 5:29, 4 users, load averages: 1.84 2.09 2.06

uptime gives the information since your system has been up and
also provide information about the average load on the system.

 1.84 => current cpu load
 2.09 => last 5 minute load
 2.06 => last 15 minute load
 load average is always depend upon the numbers of cores/cpu you have in
 your system, if system is one core than number is less then 1.0 is consider
 good same is dual core (< 2) and other cores.

We can also see in different way, consider cpu is been 100% utilized if
load is 1.0 in one core, 2.0 on dual core, 4.00 on quad core system.

 

Managing the jobs using these commands => jobs, bg, fg, & :

  • jobs: list all the running jobs on system
  • bg: make background to any job
  • fg: bring job to foreground
  • & : make process to run on background
sleep 100 &    >>>> sleep will be running on background
output >>> [1] 641

fg 
output >> [1]  + 674 running    sleep 100  >> bring to foreground

bg
output >> bring the above command to background again

jobs
output >>>  [1]  + running    sleep 10   >> display current running jobs

 

Managing process: ps, kill, pkill, pgrep, killall:

ps:

view the process and check all the system resources used by the process:

ps        >>> Give process information

PID                          TTY                    Time                       Process Name
1796                       ttys002                 0:01.20                    <process name>
31673                     ttys003                  0:00.14                    /bin/zsh --login
43537                      ttys004                 0:00.10                   <process name>
ps -l    >>> Give full information about the process including cpu used, 
              address, user id, parent process id, etc.

 UID     PID      PPID    F    CPU    PRI    NI    SZ     RSS    WCHAN    S    ADDR    TTY    TIME    CMD
1542219160 1625 1622 4006 0 31 0 2478896 348 - Ss 0 ttys001 0:00.11 <process name>
1542219160 1627 1626 4006 0 31 0 2462708 140 - S 0 ttys001 0:00.28 -zsh
ps -f    >>> get the full listing of the process and their information 
             including userid(UID), process id(PID), 
             parent process id(PPID), start time(STIME), etc...

 UID                   PID       PPID     C       STIME        TTY           TIME           CMD
1542219160    1625      1622      0        24Jul16    ttys001    0:00.11     <proess name>
1542219160    1627      1626      0        24Jul16    ttys001    0:00.28      -zsh
ps -ef   >> check all the process running on system with all users

 UID      PID      PPID      C     STIME       TTY            TIME                    CMD
 0         1         0       0     24Jul16      ??           20:03.04       /sbin/launchd
 0         41        1       0     24Jul16      ??           2:18.99          /usr/sbin/syslogd

if you want to get the specific process information you could always use the grep with above command like:  ps -ef | grep docker

However, there is one more shortcut to do that as:

pgrep docker    >>>> provide all the process ids

76
441
442
443

kill => kill the process

kill 1889  or kill -15 1889  or kill -term 1889  >>>>  Kill the process 
                                                       using pid(1889)
output >> kill the process , you can add kill -9 1889 to kill the 
          process forcefully, which will make sure that process has 
          been killed.

Some other example to kill the unresponsive process or killing forcefully :

kill -kill <process id>  or 
kill -9 <process id>  or    
kill -sigkill <process id>

pkill <name of the  process>    >>>> kill the process by name
output >> kill the process by name of the process

killall <name of the process>        >>> kill all the process which has 
                                         specific name 
output >>> kill all the process which has specific names

Different used of ‘top’ for processes =>        top command:

some usefull commands in top =>    top, kill, renice to sort and display the process

top:

top     >>> shows process with all the detail information like cpu, 
             memory, threads and everything else about the process

output:  

processes: 289 total, 2 running, 8 stuck, 279 sleeping, 1565 threads 14:26:10
Load Avg: 1.80, 1.74, 1.73 CPU usage: 5.3% user, 4.31% sys, 90.64% idle SharedLibs: 13M resident, 20M data, 0B linkedit.
MemRegions: 145620 total, 6536M resident, 89M private, 2332M shared. PhysMem: 15G used (2638M wired), 764M unused.
VM: 5116G vsize, 1064M framework vsize, 11598262(0) swapins, 13913091(0) swapouts. Networks: packets: 13933588/8804M in, 8359518/2323M out.
Disks: 3258033/89G read, 3434362/136G written.

PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPRS PGRP PPID STATE BOOSTS %CPU_ME %CPU_OTHRS UID FAULTS COW MSGSENT MSGRECV
99091 ocspd 0.0 00:02.14 4 0 63 3248K 0B 412K 99091 1 sleeping *0[1] 0.00000 0.00000 0 29666 283 8641 2724
99006 mdworker 0.0 00:11.17 4 0 59 15M 0B 296K 99006 1 sleeping *0[1] 0.00000 0.00000 1542219160 87943 243 56650 21451

if you want to run one iteration of top, you can run:

top -n 1       >> run one iteration (only one line)
output >> Same output as above with only one line

top -n 2 -d 3       >> if you want to run the top command for 
                        <for certain time in seconds>          
                        use -d <time in second> option
output >> Same output as above but will exist after 3 seconds

Tips:

  • By default top command display the process in cpu sorted way, if you want to sort                                 by memory:  top -o %Mem(Linux) or top -m Mem (mac)
  • Linux:  You can also press ‘shift + f’ to show different options to sort the display                  and enter any of the options to sort
  • Ctrl + C to quite the top command

renice:

change the priority of the command like
renice <priority> pid
renice 21 2345    >>> change the priority of the pid to 19
  • You cannot change the priority of the pid which you don’t own.
  • You can not start the process with nice value less than 20

 

 

Advertisements

One thought on “procps tool on Linux for process

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: