Linux Process Related Commands

Process Related Command Examples

– To see the zombie process
    # ps aux | awk ‘{ print $8 ” ” $2 }’ | grep -w Z

– To list the running processes
    # ps -r

– Processes for a particular user
    # ps -U apache
    # ps U apache
    # ps -u apache

– To view processe owned by current user.
    # ps U $USER

– To print a stack trace of a running process.
    # pstack 1691
        #0  0x00ef7424 in __kernel_vsyscall ()
        #1  0x00649623 in __waitpid_nocancel () from /lib/libc.so.6
        #2  0x08082ec2 in ?? ()
        #3  0x080840ee in wait_for ()
        #4  0x08074515 in execute_command_internal ()
        #5  0x08074684 in execute_command ()
        #6  0x08060797 in reader_loop ()
        #7  0x0805fe19 in main ()

– To lit process with the virtual memory format
    # ps v

– To display a tree of processes.
    # pstree

– pgrep, pkill – look up or signal processes based on name and other attributes
    # pgrep 1234
    # pkill 1234 OR # pkill httpd

– To find top processes using memory
    # ps -eo pid,rss,comm –sort rss

– Top 10 processes consuming more memory
    # ps ax -o rss,command | sort -nr | head -n 10
    # ps ax -o rss,user,command | sort -nr | head -n 10
    # watch -n 2 ‘ps ax -o rss,user,command | sort -nr | head -n 10’

– To list the processes which has tatad.pl in its command execution.
    # ps -f -C tatad.pl

– List the processes based on PIDs
    # ps -f –ppid 9576

– To list the process hierarchy
    # ps -e -o pid,args –forest
    # ps axjf
    # ps -ejH

– To list elapsed wall time for processes
    # ps -p 1,29675 -o pid,etime=

– List all threads for a particular process
    # ps -C java -L -o pid,tid,pcpu,state,nlwp,args

– To find the memory leak, fire below command
    # ps aux –sort pmem

– We can customize the output using the -o option.  

–  To list the memory usage periodically
    # free -m -s 5
    # free -t -m
    # vmstat 5

– Sorting processes by memory
    # ps aux | awk ‘{print $4″t”$11}’ | sort | uniq -c | awk ‘{print $2″ “$1” “$3}’ | sort -nr
    # ps aux –sort -rss | head -n 10


    # ps ef -o command,vsize,rss,%mem,size
    # ps -e -orss=,args= | sort -b -k1,1n
    # ps aux | sort -nrk 4 | head -10
    # top -n 1
    # ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | more
    # ps -e -orss=,size=,args= | sort -b -nr

– To know memory map of a process
    # pmap -x 1232

– To get the process start time
    # ps -p PID -o lstart=

– To kill the process
    # kill -9 PID ( sends a process a SIGKILL signal)

– The kill command allows a user to send signals to processes. ( It is nothing but sending signals to processes.)

– A process can be sent a SIGTERM signal in four ways (the process ID is ‘1234’ in this case):
    kill 1234
    kill -s TERM 1234
    kill -TERM 1234
    kill -15 1234

– The process can be sent a SIGKILL signal in three ways:
    kill -s KILL 1234
    kill -KILL 1234
    kill -9 1234

– Typing certain key combinations at the controlling terminal of a running process causes the system to send it certain

signals:

    Ctrl-C sends an INT signal (SIGINT); causes the process to terminate.

    Ctrl-Z sends a TSTP signal (SIGTSTP); causes the process to suspend execution.

    Ctrl- sends a QUIT signal (SIGQUIT); causes the process to terminate and dump core.

– Variations for sending -9 signal.
    # kill -s SIGKILL 1414
    # kill -s KILL 1414
    # kill -s 9 1414
    # kill -SIGKILL 1414
    # kill -KILL 1414

– To list all signalks from the linux enviroment.
    # man -k signal | grep list

– To kill a background job.
    # kill %1

– To kill more than one process
    # kill pid1 pid2 pid3 pid4…..

————————————————————————————————————————————————–
We request and encourage you to leave a comment or share if you have more information / examples so as to keep this blog more informative, to benefit everyone of us.
————————————————————————————————————————————————–

Leave a Reply

Your email address will not be published. Required fields are marked *