FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 12-23-2010, 06:46 AM
Bob Proulx
 
Default how to get pid when I start the process

Zhang Weiwu wrote:
> 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.

You might try using the ps show process hierchy options to show the
parent child relationship of processes. You are wanting to kill the
parent process.

SysV-like (my personal preference):

ps -efH

BSD-like

ps axf

But do you need to see all processes? Won't you be the owner of that
process?

ps xf

> 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?

The best answer is to have the deamon write a pid file itself. I am
not familiar with amuled and did not install it to investigate but
if it could write a pidfile then you could kill the right pid without
mistake. I assume not though or I assume you would already be using it.

You could use 'killall' to kill all processes named amuled. I would
guess that this is your best answer. Searching the web briefly tells
me that the --ignore-case option may be needed here.

killall --ignore-case amuled

Alternatively 'pkill' also has a rich set of option controls for
killing processes by name.

If amuled has an option *not* to fork into the background then you
could use that option and then fork into the background yourself after
writing a pidfile. This is sometimes used by /etc/init.d scripts when
working with daemons with similar issues. The Debian rsync init.d
script uses this technique for one example.

Bob
 
Old 12-23-2010, 07:21 AM
Chris Davies
 
Default how to get pid when I start the process

Zhang Weiwu <zhangweiwu@realss.com> wrote:
> 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.

Er, no. To be pedantic and accurate, you should kill the process started
first. Given that PIDs wrap around from high numbers back to low numbers,
that doesn't always mean the lowest. (It might seem to be the lowest on
a relatively little used personal system that's rebooted daily, but you
cannot guarantee this expectation in all circumstances.)

Without knowing much about amuled, could you reliably use this? -

kill $(ps ax | awk '$6=="amuled" && $4=="R" {print $1}')

Chris


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: lddbu7xs5i.ln2@news.roaima.co.uk">http://lists.debian.org/lddbu7xs5i.ln2@news.roaima.co.uk
 

Thread Tools




All times are GMT. The time now is 08:09 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org