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:
zhangweiwu@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
zhangweiwu@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!
Hi ,
As already mentioned by Bob Proulx pkill & pgrep are better than ps for
such kind of tasks .
Reagrds ,
Alex
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Zhang Weiwu writes:
> 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?
man killall
man pidof
--
John Hasler
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 87zkrwd1o9.fsf@thumper.dhh.gt.org">http://lists.debian.org/87zkrwd1o9.fsf@thumper.dhh.gt.org
12-23-2010, 03:29 PM
Bill Dennen
how to get pid when I start the process
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:
>
> zhangweiwu@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
> zhangweiwu@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 $$ ??
--
>@<
Bill Dennen ieee1014@hotmail.com
Of all the things I miss, I miss my mind the most ...
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: ievtcv$lt9$1@speranza.aioe.org">http://lists.debian.org/ievtcv$lt9$1@speranza.aioe.org
12-24-2010, 02:48 AM
Richard Hector
how to get pid when I start the process
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:
> >
> > zhangweiwu@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
> > zhangweiwu@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:
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1293162505.679.5.camel@topaz.wgtn.cat-it.co.nz">http://lists.debian.org/1293162505.679.5.camel@topaz.wgtn.cat-it.co.nz
12-25-2010, 02:23 AM
Bob Proulx
how to get pid when I start the process
Richard Hector wrote:
> $$ 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`
Since presumabely amuled forks itself into the background then putting
it into the background at launch won't leave the right pid in $!.
That will be the pid of the shell but not the pid of the backgrounded
amuled.
Bob
12-26-2010, 03:45 AM
Zhang Weiwu
how to get pid when I start the process
Several people offered advise. The trick is really how to locate and
kill the parent process, because I have tried otherwise and failed.
Following suggestion from Bob Proulx, killing all processes would ends
up with corrupted temporary files in my case. Bob wrote in detail
explanation of how thinks works which should serve great reference
material for new reader/learners on the list.
One idea offered by Chris Davies is to find the process with R tag, but
I tried and end up feeling that one isn't always the parent process.
Bill Dennen and Richard Hector together offered the advice to run the
process in foreground and sink them to background with shell '&'
postfix, and then obtaining the sunken process' ID from the shell using
special '$!', which works wonderfully for me, thus solved the case.
Thanks all for comments.
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4D16C883.8030109@realss.com">http://lists.debian.org/4D16C883.8030109@realss.com