commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
If you want a visual representation of the parent/child relationships between processes, this is one easy way to do it. It's useful in debugging collections of shell scripts, because it provides something like a call traceback.
When a shell script breaks, just remember "awwfux".
It's like `prstat -t` under Solaris
This command will show the 20 processes using the most CPU time (hungriest at the bottom).
You can see the 20 most memory intensive processes (hungriest at the bottom) by running:
ps aux | sort +3n | tail -20
Or, run both:
echo "CPU:" && ps aux | sort +2n | tail -20 && echo "Memory:" && ps aux | sort +3n | tail -20
I find it ugly & sexy at the same time isn't it ?
This command kills all processes with 'SomeCommand' in the process name. There are other more elegant ways to extract the process names from ps but they are hard to remember and not portable across platforms. Use this command with caution as you could accidentally kill other matching processes!
xargs is particularly handy in this case because it makes it easy to feed the process IDs to kill and it also ensures that you don't try to feed too many PIDs to kill at once and overflow the command-line buffer.
Note that if you are attempting to kill many thousands of runaway processes at once you should use 'kill -9'. Otherwise the system will try to bring each process into memory before killing it and you could run out of memory. Typically when you want to kill many processes at once it is because you are already in a low memory situation so if you don't 'kill -9' you will make things worse
This finds a process id by name, but without the extra grep that you usually see. Remember, awk can grep too!
Want to know why your load average is so high? Run this command to see what processes are on the run queue. Runnable processes have a status of "R", and commands waiting on I/O have a status of "D".
On some older versions of Linux may require -emo instead of -eo.
On Solaris: ps -aefL -o s -o user -o comm | egrep "^O|^R|COMMAND"
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1828 0.0 0.0 5396 476 ? Ss 2008 0:00 /usr/sbin/sshd
the $15 may change for you depending on your distro, etc...
This is a nice way to kill processes.. the example here is for firefox!!! substitute firefox for whatever the process name is...
Yet another ps grep function, but this one includes the column headings.
My variant on this common function. Some highlights:
Allows you to override the default ps args of "aux"
Uses bracket trick to omit the grep process itself without having to use a second grep
Always prints the correct header row of ps output
Limitations: Ugly ps error output if you forget to quote your multi word grep argument
This comes in handy if you have daemons/programs that have potential issues and stop/disappear, etc., can be run in cron to ensure that a program remains up no matter what. Be advised though, if a program did core out, you'd likely want to know why (gdb) so use with caution on production machines.