parsed.org

Tips by tag: process

find all ocurrences for a command (in this case python) :

awk '{for(i = 11; i <= NF; i++) printf $i " "; printf "n"}' < <(ps aux | grep python)

kill all ocurrences for a command (python again) :

ps aux | grep python | awk {'print "kill " $2'} | bash

also can be added the -9 signal

ps aux | grep python | awk {'print "kill -9 " $2'} | bash
awkprocessps
Background Process by xinu on Dec 31, 2005 04:10 PM

If you need a process to survive your logging out of the system (or being knocked off of it), you can either screen it or wrap it with nohup. If you nohup, you'll lose control of it entirely, but the output will be written to nohup.out. With screen you can re-attach and take control later:

# nohup program -opts args &

-or-

# screen (press 'ctrl+a d' to detach after you've run the proc)
commandsloginlogoutnohupprocessscreenshell
Changing Process Priority by xinu on Mar 10, 2005 01:52 PM

Ever been on a machine that was ailing and just wouldn't respond? As soon as you're root, lower the priority of the offending process ID(s) (in this example, 1103) by using the 'renice' command:

# renice -19 1103
commandsconfigurationcontroldebuggingmonitoringpriorityprocessrecoveryrenicerescuesecurityshell
Find the Hog by xinu on Sep 10, 2005 12:00 AM

If you need to find the process hogging your CPU, try this:

$ ps aux | awk '!/root|nobody/ { if ($4>2) {print $2}}'
awkcpuownerpipeprocessrootshelluser
Network Forensics by cygnus on Jan 21, 2005 08:31 AM

You can use the lsof (LiSt Open Files) utility to view information about which processes own file handles on a system. Since sockets map to file descriptors, lsof will show you which processes own socket connections. If you see that your machine is connected to another on TCP port 6234 (source or dest) and you want to find out which process(es) are responsible for the connection, run:

# lsof -ni tcp:6234

Note that when run as an unprivileged user, lsof will only show you file descriptors that you have permission to see. You must run lsof as root to see everything in the kernel.

commandsconnectionsdebuggingdescriptorsfilesystemlsofmonitoringnetworkpermissionsprocesssocketsutilities
Process Substitution by cygnus on Jan 20, 2005 10:16 AM

Zsh can run a command and let you do things with a temporary file with the resulting output:

$ emacs -nw =(ps aux)

This will create a temporary file with the output of ps aux and let you edit it in Emacs. Or:

$ diff =(ls) =(ls -F)

Will run diff on the output of the two commands.

diffemacsprocesssubstitutionzsh
Using 'strings' for Paths in a Binary by xinu on Sep 13, 2005 02:34 PM

If you need to discover on which paths a binary depends, you can sometimes run strings on it and grep for everything starting with a slash:

# strings /usr/sbin/named | grep ^/
/lib/ld-linux.so.2
/etc/named.conf
/etc/rndc.key
/etc/lwresd.conf
/etc/resolv.conf
/var/run/named/named.pid
/var/run/named/lwresd.pid
/dev/null
binaryconfigurationgrepprocessshellstrings
RSS