On Thu, 2010-12-23 at 16:29 +0000, Bill Dennen wrote:
> On Thu, 23 Dec 2010 08:30:02 +0100, Zhang Weiwu scribbled:
> 
> > Hello. I usually start amuled and kill it after a few hours, I do such
> > thing once a day. Usually I do it like this:
> > 
> > In one console:
> > $ amuled
> > 
> > In another:
> > 
> > zhangwe...@mesopotamia:~$ ps ax | grep mule 13595 zhangwei 14080 R N 
> > amuled
> > 13598 zhangwei 14080 S N  amuled
> > 13600 zhangwei 14080 S N  amuled
> > 13603 zhangwei 14080 S N  amuled
> > 13612 zhangwei  1352 S    grep mule
> > zhangwe...@mesopotamia:~$ kill 13595
> > 
> > Note that I should always kill the least-numbered process, I tried
> > otherwise and always end up in trouble.
> > 
> > Question is, how do I script-lize this? The only difficulty is to get
> > the pid in script. I could use an one-liner awk script to analyses the
> > output of ps, but that sounds overkill. Is there a better way?
> > 
> > Best. & Thanks in advance!
> 
> Is not the PID returned in $$ ??

$$ is the pid of the current shell.

$! is the pid of the most recent background process, so you could do:

amuled & echo $! > amuled.pid
...
kill `cat amuled.pid`

or:

amuled & A_PID=$!
sleep 60
kill $A_PID


Richard



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1293162505.679.5.ca...@topaz.wgtn.cat-it.co.nz

Reply via email to