samedi 29 novembre 2014

ps to show only processes that match more than one condition (AND)


According to the ps man page:



Except as described below, process selection options are additive. The default selection is discarded, and then the selected processes are added to the set of processes to be displayed. A process will thus be shown if it meets any of the given selection criteria.



I take this to mean that the matches are "OR"ed, not "AND"ed.


I am developing my own locking script which creates a directory (mkdir mutex) and writes PPID and PID information to a file in this dir. One of the functions in the script is to clean up stale lock files by looping through all lock files, and extracting $PPID and $PID. It next determines if a process which has PID $PID and PPID $PPID is still running.


However with ps I am getting all processes which have PPID $PPID, and I'm also getting PID $PID. I want it to show me only the process with pid $PID and ppid $PPID


I understand grep is intuitively useful here, but is there a "less expensive" method to use? Perhaps another process-related utility?




procps-3.2.7-16.el5



Aucun commentaire:

Enregistrer un commentaire