Commands tagged ps (86)

  • awk is evil! Show Sample Output


    22
    ps hax -o user | sort | uniq -c
    buzzy · 2010-04-29 10:43:03 13
  • exec -a $NAME $COMMAND $ARGS `your_cmd -erase_all_files` is the real process, but harmless-looking getty appears in the process table. Never actually had a need to do this, but interesting nonetheless... Tested in bash, dash. -a $NAME "pass NAME as the zeroth argument to COMMAND", i.e. customise the name of the process (as commonly seen with `ps`) Show Sample Output


    16
    exec -a "/sbin/getty 38400 tty7" your_cmd -erase_all_files
    mhs · 2012-02-01 10:54:03 8
  • top accecpts a comma separated list of PIDs.


    15
    top -p $(pgrep -d , foo)
    michelsberg · 2012-06-27 20:59:09 6
  • ps and grep is a dangerous combination -- grep tries to match everything on each line (thus the all too common: grep -v grep hack). ps -C doesn't use grep, it uses the process table for an exact match. Thus, you'll get an accurate list with: ps -fC sh rather finding every process with sh somewhere on the line. Show Sample Output


    14
    ps -fC PROCESSNAME
    pooderbill · 2015-04-20 13:09:44 17
  • you can also pipe it to "tail" command to show 10 most memory using processes. Show Sample Output


    13
    ps aux --sort=%mem,%cpu
    mrwill · 2009-10-10 22:48:51 7
  • I don't truly enjoy many commands more than this one, which I alias to be ps1.. Cool to be able to see the heirarchy and makes it clearer what need to be killed, and whats really going on. Show Sample Output


    8
    command ps -Hacl -F S -A f
    AskApache · 2009-08-19 07:08:19 10
  • This one-liner will use strace to attach to all of the currently running apache processes output and piped from the initial "ps auxw" command into some awk. Show Sample Output


    7
    ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace
    px · 2011-03-14 21:45:22 34
  • to omit "grep -v", put some brackets around a single character


    6
    watch "ps auxw | grep [d]efunct"
    alvinx · 2009-08-12 08:11:16 4
  • enumerates the number of processes for each user. ps BSD format is used here , for standard Unix format use : ps -eLf |awk '{$1} {++P[$1]} END {for(a in P) if (a !="UID") print a,P[a]}' Show Sample Output


    6
    ps aux |awk '{$1} {++P[$1]} END {for(a in P) if (a !="USER") print a,P[a]}'
    benyounes · 2010-04-28 15:25:18 3
  • faster ;) but your idea is really cool


    6
    ps -ef | grep c\\ommand
    ioggstream · 2011-01-04 11:43:14 4
  • Shows all those processes; useful when building some massively forking script that could lead to zombies when you don't have your waitpid()'s done just right.


    5
    watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
    coffeeaddict_nl · 2009-08-11 12:22:13 4
  • pgrep foo may return several pids for process foobar footy01 etc. like this: 11427 12576 12577 sed puts "-p " in front and we pass a list to top: top -p 11427 -p 12576 -p 12577


    5
    top $(pgrep foo | sed 's|^|-p |g')
    michelsberg · 2012-06-14 15:13:00 3
  • An easy function to get a process tree listing (very detailed) for all the processes of any gived user. This function is also in my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    4
    psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
    AskApache · 2009-11-13 06:10:33 4
  • This command will add up RAM usage of all processes whose name contains "java" and output the sum of percentages in HRF. Also, unlike the original #15430, it wont fail on processes with a usage of >9.9%. Pleases note that this command wont work reliably in use cases where a significant portion of processes involved are using less than 0.1% of RAM, because they will be counted as "0", even though a great number of them could add up to significant amounts. Show Sample Output


    4
    ps -eo pmem,comm | grep java | awk '{sum+=$1} END {print sum " % of RAM"}'
    bugmenot · 2016-02-10 09:00:56 16
  • Referring to the original post, if you are using $! then that means the process is a child of the current shell, so you can just use `wait $!`. If you are trying to wait for a process created outside of the current shell, then the loop on `kill -0 $PID` is good; although, you can't get the exit status of the process.


    3
    wait $!
    noahspurrier · 2010-06-07 21:56:36 4
  • Like the original version except it does not include the parent apache process or the grep process and adds "sudo" so it can be run by user.


    3
    ps h --ppid $(cat /var/run/apache2.pid) | awk '{print"-p " $1}' | xargs sudo strace
    colinmollenhour · 2012-03-21 01:59:41 3
  • Like command 10870, but no need for sed


    3
    top '-p' $(pgrep -d ' -p ' foo)
    __ · 2012-06-27 18:32:03 6
  • Finding high memory usage report in human readable format. Show Sample Output


    3
    ps -eo size,pid,user,command --sort -size |awk '{hr[1024**2]="GB";hr[1024]="MB";for (x=1024**3; x>=1024; x/=1024){if ($1>=x){printf ("%-6.2f %s ", $1/x, hr[x]);break}}}{printf ("%-6s %-10s ", $2, $3)}{for (x=4;x<=NF;x++){printf ("%s ",$x)} print ("\n")}'
    rockon · 2012-11-27 04:29:08 11
  • Show the command line for a PID with ps


    3
    ps h -o %a 21679
    BeniBela · 2015-09-27 11:00:07 13
  • Will open strace on all apache process, on systems using sbin/apache (debian) or sbin/httpd (redhat), and will follow threads newly created.


    3
    ps auxw | grep -E 'sbin/(apache|httpd)' | awk '{print"-p " $2}' | xargs strace -F
    gormux · 2016-08-04 10:59:58 14
  • Short list about top 10 processes, sorted by CPU usage Show Sample Output


    3
    ps aux | sort -rk 3,3 | head -n 10
    x3mboy · 2018-10-29 20:00:36 495

  • 3
    ps auxk -%cpu | head -n10
    rolanda · 2019-06-29 19:17:14 46
  • I've wanted this for a long time, finally just sat down and came up with it. This shows you the sorted output of ps in a pretty format perfect for cron or startup scripts. You can sort by changing the k -vsz to k -pmem for example to sort by memory instead. If you want a function, here's one from my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html aa_top_ps(){ local T N=${1:-10};T=${2:-vsz}; ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -${T} -A|sed -u "/^ *PID/d;${N}q"; } Show Sample Output


    2
    command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'
    AskApache · 2010-05-18 18:41:38 6
  • Shows a list of users that currently running processes are executing as. YMMV regarding ps and it's many variants. For example, you might need: ps -axgu | cut -f1 -d' ' | sort -u Show Sample Output


    2
    ps -eo user | sort -u
    dfaulkner · 2010-07-07 12:28:44 6
  • While going through the source code for the well known ps command, I read about some interesting things.. Namely, that there are a bunch of different fields that ps can try and enumerate for you. These are fields I was not able to find in the man pages, documentation, only in the source. Here is a longer function that goes through each of the formats recognized by the ps on your machine, executes it, and then prompts you whether you would like to add it or not. Adding it simply adds it to an array that is then printed when you ctrl-c or at the end of the function run. This lets you save your favorite ones and then see the command to put in your .bash_profile like mine at : http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Note that I had to do the exec method below in order to pause with read. t () { local r l a P f=/tmp/ps c='command ps wwo pid:6,user:8,vsize:8,comm:20' IFS=' '; trap 'exec 66 exec 66 $f && command ps L | tr -s ' ' >&$f; while read -u66 l >&/dev/null; do a=${l/% */}; $c,$a k -${a//%/} -A; yn "Add $a" && P[$SECONDS]=$a; done } Show Sample Output


    2
    for p in `ps L|cut -d' ' -f1`;do echo -e "`tput clear;read -p$p -n1 p`";ps wwo pid:6,user:8,comm:10,$p kpid -A;done
    AskApache · 2010-10-12 06:42:10 7
  •  1 2 3 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

force unsupported i386 commands to work on amd64
The above was done using the i386 flashplayer plugin, and was installed on a AMD64 machine running an AMD64 kernel and AMD64 programs. the resulting plugin install ultimately didn't work for swiftfox (but worked for iceweasel) without also covering it with a nspluginwrapper which took a bit of fenangaling to get to work (lots of apt-getting) but it is a nice feature to be able to trick installers that think you need i386 into running on a amd64, or at least attempting to run on amd64. Enjoy

Gets the english pronunciation of a phrase
Usage examples: say hello say "hello world" say hello+world

Generat a Random MAC address
Generate a random MAC address with capital letters

Extract tarball from internet without local saving

Check whether laptop is running on battery or cable
The original proc file doesn't exist on my system.

Install pip with Proxy
Installs pip packages defining a proxy

Track X Window events in chosen window
After executing this, click on a window you want to track X Window events in. Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo"

dont execute command just add it to history as a comment, handy if your command is not "complete" yet

list files recursively by size

Get the IP address
gives u each configured IP in a seperate line.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: