service; ps & grep help

Sjoerd Mullender sjoerd at acm.org
Mon Aug 25 13:38:16 UTC 2008


Anders Karlsson wrote:
> * James Pifer <jep at obrien-pifer.com> [20080825 15:03]:
>> I could use a little help with ps and grep. When running a command like:
>>
>> # ps -ewf | grep sendmail
>> root      2730     1  0 Jul14 ?        00:00:01 sendmail: accepting connections
>> smmsp     2739     1  0 Jul14 ?        00:00:00 sendmail: Queue runner at 01:00:00 for /var/spool/clientmqueue
>> root      6500  6362  0 07:51 pts/3    00:00:00 grep sendmail
> 
> Try
> # ps -ef | grep [s]endmail
> instead. Should do what you want (does for me anyway).

Even easier:

pgrep sendmail

will just print the process ID of sendmail.  Nothing else.
Also look at pkill.  You'll need to yum install procps if you don't have
it already.

>> Is there any way to run this command and get these results, but exclude
>> the actual grep itself, which is the last line?
>>
>> A little background, I have a java based application that I've used a
>> custom start and stop script for. Basically the stop script does:
>> stop() {
>>         for pid in `ps -efww | grep myapp | grep -v grep | cut -b 10-15`;do
>>                 #echo $pid
>>                 kill -9 $pid
>>         done
>>     RETVAL=$?
>>     return $RETVAL
>> }
> 
> Well, in a shell, $$ is the PID. If you can capture your process PID
> when it starts, you simply write it in a file in /var/run/ and when
> you stop, you issue a "kill -9 $(</var/run/pidfile)".
> 
>> This has worked for years, but for some reason it has stopped working. I
>> think it may be because the process is killing itself before it kills
>> the app?
>>
>> I assume the correct way to do this is store the pid in a file that you
>> reference, but I haven't figured out how to do that yet. 
>>
>> Any help is appreciated. 
> 
> You can have a look at various init scripts in /etc/init.d/ to get an
> idea about how they done it.
> 
> /Anders
> 


-- 
Sjoerd Mullender

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 369 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20080825/469eea77/attachment-0001.sig>


More information about the fedora-list mailing list