On Tue, Jan 29, 2008 at 02:54:14PM +0100, Helmut Schneider wrote:
> pierre <[EMAIL PROTECTED]> wrote:
>> On Tue, 29 Jan 2008 11:37:41 +0100
>> "Helmut Schneider" <[EMAIL PROTECTED]> wrote:
>>
>>> Claudio Jeker <[EMAIL PROTECTED]> wrote:
>>>> We don't believe in pid files. Use pgrep(1) and pkill(1) instead,
>>>> you will never have stale info that way.
>>>
>>> pgrep on OpenBSD does not support '-o' (Select only the oldest). It
>>> is - well - it could be more useful.
>>>
>> man pgrep
>> -n      Match only the most recently created process, if any.
>>
>> Is that what you're looking for ?
>
> Not at all. I might find a child but I will never find the parent.
>
> [EMAIL PROTECTED] ~]# pgrep -fl httpd
> 81972 /usr/local/sbin/httpd
> 81960 /usr/local/sbin/httpd
> 1115 /usr/local/sbin/httpd
> 1114 /usr/local/sbin/httpd
> 1111 /usr/local/sbin/httpd
> 1109 /usr/local/sbin/httpd
> 1108 /usr/local/sbin/httpd
> 979 /usr/local/sbin/httpd
> [EMAIL PROTECTED] ~]#
>
> To stop httpd, which pid should I kill, the oldest, or the most recent?
>
> OK, 'pgrep -fl httpd | tail -1' does the trick, and pgrep is not safe 
> enough for finding parents, but...

If you really want to find the parent you can...

$ ps ax -O pgid | grep ntpd
 4887  4887 ??  Is      0:00.01 ntpd: [priv] (ntpd)
 7164  4887 ??  I       0:00.06 ntpd: ntp engine (ntpd)

The header that gets stripped by grep:
  PID  PGID TT  STAT       TIME COMMAND

So you can see that for one process PID==PGID. Bingo.

-- 
Darrin Chandler            |  Phoenix BSD User Group  |  MetaBUG
[EMAIL PROTECTED]   |  http://phxbug.org/      |  http://metabug.org/
http://www.stilyagin.com/  |  Daemons in the Desert   |  Global BUG Federation

Reply via email to