xprop and pgrep
Tuesday, March 28, 2006 2:43:14 PM
xprop are use to display the property for any X item, you can just type xprop at your terminal and click on any X item you like to check the properties. You can type xprop -root to check the root windows properties and also other active programs, for example gaim.
xprop -name gaim
To grep the process ID for the active 'gaim', you can put
xprop -name gaim | grep PID
Here comes in another command with more simple result which returns you only the pid.
Bare in mind, if you have multiple same services running, it will return a list of pid, let say apache2. To kill process based on the id, now you may do so with
kill `pgrep gaim`
It always have another way to do it, simply killall gaim will do the same thing. But pgrep did more than that, you can list all process created by root user with
This will list all the process running by root with the process names.
pgrep -l -u root
Combine ps and pgrep to display the details of a process with name apache2
ps -fp `pgrep -d' ' -x apache2`
This 2 lines does the same thing as above.
ps aux | grep apache2 ps -fp $(pgrep -d' ' -x apache2)