Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Create a pidof command to find PID numbers easily' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a pidof command to find PID numbers easily
Authored by: jdmuys on Oct 29, '09 07:00:20AM

This solution and the comments that I read have a flaw: they won't work for a command line tool.

The reason is that "ps -A" doesn't list command-line tools launched from the terminal. ("top" does, but that doesn't help much).

I wasn't able to find an option combination that would work for ps.

So are we stuck? Well, I found a way that works, inspired by this thread:

killall -s -c ToolName | grep -e [:digit:] | awk '{print $3}'

the idea is that killall -s will "simulate" the kill, and not do it. I then can parse the result.

As for the use case, mine is for the leaks command that wants a pid. When iterating on development, each run yields a different pid. so its useful to have a way to go from process name to pid.

Now I can do:

leaks `killall -s -c ToolName | grep -e [:digit:] | awk '{print $3}'`

Caveat: I'm really a Unix newbie. There might be a better solution. But mine works for me, while the previous ones didn't (on Snow Leopard).



[ Reply to This | # ]