pgrep not finding some running processes?

I was writing a script on my machine that at one point needed to see if sshd was running. I was using pgrep, and while I initially thought I had made a mistake in my script, I found that no matter what I did, [CMD="pgrep"]sshd[/CMD] would not return any PIDs. However, it is most definitely running, as am using the machine over SSH. I can pgrep other processes that are running without issue. Also, I can see sshd just fine with [CMD="ps"]-ax | grep sshd[/CMD] and [CMD="top"]-t[/CMD]

Lastly, I don't know if it matters, but I'm using the openssh-portable from ports. And, FWIW:
Code:
$ uname -mrs
FreeBSD 8.1-RELEASE-p2 i386
...and this happens on all my FBSD systems that are in the same configuration, not just the one.
 
I apologize for offtop, but I wonder in what way you upgraded FreeBSD? I see that You have RELEASE-p2. Strange. I updated my FreeBSD via freebsd-update utility, and uname does not show patch, on second level. How did You make that?
You know, I even wrote a topic about that, in section "Installing and upgrading". I learned that the latest SA not touched kernel, so uname does not show p2.

Thanks for reply.


EDIT
Fact, there is also opportunity to update FreeBSD from source.
 
anomie said:
Try:
% pgrep -f sshd
And read the pgrep(1) manpages to see what that does.

I'm not quite sure how the security/openssh-portable daemon appears in FreeBSD's process table. (i.e. I am not running it.)
This still doesn't find any PIDs. :(

francis said:
I apologize for offtop, but I wonder in what way you upgraded FreeBSD? I see that You have RELEASE-p2. Strange. I updated my FreeBSD via freebsd-update utility, and uname does not show patch, on second level. How did You make that?
You know, I even wrote a topic about that, in section "Installing and upgrading". I learned that the latest SA not touched kernel, so uname does not show p2.

Thanks for reply.
I do my upgrades from source, not binary distributions.
 
Ah, thanks, that works. However, from reading the documentation, it's not exactly clear to me why sshd is considered an ancestor of pgrep.
 
To answer this you need to provide output of
$ ps adx
Most likely you're issuing pgrep from under same sshd (client) session that is a descendant of currently running sshd (daemon) on that box, e.g.
Code:
$ ps adx
  PID  TT  STAT      TIME COMMAND
    0  ??  DLs   11:02.59 [kernel]
    1  ??  ILs    0:00.06 - /sbin/init --
 1981  ??  Is     0:00.00 |-- /usr/sbin/sshd
 2106  ??  Is     0:00.11 | `-- sshd: luser [priv] (sshd)
 2108  ??  S      0:00.12 |   `-- sshd: luser@pts/0 (sshd)
 2109   0  Ss+    0:00.13 |     `-- screen -xRS main
 2110  ??  Ss     0:00.14 |       `-- screen -xRS main
 2112   1  Ss     0:00.54 |         `-- /usr/local/bin/zsh
 3319   1  R+     0:00.01 |           `-- ps adx
 
Alternatively, you can use -lf which looks at the entire line of output from ps, instead of just the command name. $ pgrep -lf sshd
 
Back
Top