|
Home > Archive > Unix Programming > November 2007 > killing a large lists of pids
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
killing a large lists of pids
|
|
| K-mart Cashier 2007-11-29, 1:30 pm |
| Say I have the following list of pids...
8, 2, 5, 4, 3, 9, 7, 11
I've seen some code where people would sort the pids before killing
them. What is the possible advantage of this? If you already have the
list of pids, couldn't you just traverse the list, killing each one
along the way?
Chad
| |
| Joachim Schmitz 2007-11-29, 1:30 pm |
| "K-mart Cashier" <cdalten@gmail.com> schrieb im Newsbeitrag
news:b8fd69dd-8498-491b-8e91-b84f281de196@s19g2000prg.googlegroups.com...
> Say I have the following list of pids...
> 8, 2, 5, 4, 3, 9, 7, 11
>
> I've seen some code where people would sort the pids before killing
> them. What is the possible advantage of this? If you already have the
> list of pids, couldn't you just traverse the list, killing each one
> along the way?
Guess the reason is that typically the parent processes have lower PIDs and
killing parents may take the children along
Bye, Joo
| |
| Benoit Lefebvre 2007-11-29, 1:30 pm |
| On Nov 29, 8:54 am, K-mart Cashier <cdal...@gmail.com> wrote:
> Say I have the following list of pids...
> 8, 2, 5, 4, 3, 9, 7, 11
>
> I've seen some code where people would sort the pids before killing
> them. What is the possible advantage of this? If you already have the
> list of pids, couldn't you just traverse the list, killing each one
> along the way?
>
> Chad
for pid in "8 2 5 4 3 9 7 11"
do
kill $pid
done
| |
| K-mart Cashier 2007-11-29, 1:30 pm |
| On Nov 29, 6:41 am, Benoit Lefebvre <benoit.lefeb...@gmail.com> wrote:
> On Nov 29, 8:54 am, K-mart Cashier <cdal...@gmail.com> wrote:
>
>
>
>
> for pid in "8 2 5 4 3 9 7 11"
> do
> kill $pid
> done
One some "idle" killers for both the IRC and FreeBSD, the programmer
would like like
getpids
sort pids
kill user process that didn't hit ctrl-d
getpids
sortpids
kill detached processes
getpids
sortpids
kill daemons of users that aren't looged in
| |
| shakahshakah@gmail.com 2007-11-29, 1:30 pm |
| On Nov 29, 9:41 am, Benoit Lefebvre <benoit.lefeb...@gmail.com> wrote:
> On Nov 29, 8:54 am, K-mart Cashier <cdal...@gmail.com> wrote:
>
>
>
>
> for pid in "8 2 5 4 3 9 7 11"
> do
> kill $pid
> done
Depending on what you're trying to demonstrate, don't you have to lose
the dquotes, e.g.:
for pid in 8 2 5 4 3 9 7 11
do
kill $pid
done
?
| |
| fjblurt@yahoo.com 2007-11-29, 1:30 pm |
| On Nov 29, 5:54 am, K-mart Cashier <cdal...@gmail.com> wrote:
> Say I have the following list of pids...
> 8, 2, 5, 4, 3, 9, 7, 11
>
> I've seen some code where people would sort the pids before killing
> them. What is the possible advantage of this? If you already have the
> list of pids, couldn't you just traverse the list, killing each one
> along the way?
Of course. I think the only reason to sort would be for "neatness",
the same reason glob(3) sorts its output. For example, if some of the
kills fail, the error messages will appear in numerical order, which
might make them easier to read. But there's no functional reason that
I can imagine.
| |
| William Ahern 2007-11-29, 7:21 pm |
| fjblurt@yahoo.com wrote:
> On Nov 29, 5:54 am, K-mart Cashier <cdal...@gmail.com> wrote:
[vbcol=seagreen]
> Of course. I think the only reason to sort would be for "neatness",
> the same reason glob(3) sorts its output. For example, if some of the
> kills fail, the error messages will appear in numerical order, which
> might make them easier to read. But there's no functional reason that
> I can imagine.
Especially on systems like OpenBSD, which randomize PIDs.
| |
| J de Boyne Pollard 2007-11-29, 7:21 pm |
| JS> Guess the reason is that typically the parent processes have
JS> lower PIDs and killing parents may take the children along
But, conversely, killing the children first would often tend to cause
the parents to exit of their own accord, if (for example) the parents
were shells executing a command pipeline.
Both of these are superficially attractive rationales. But they both
break down. In reality, process IDs are not guaranteed to be created
in _any_ order. So sorting process IDs into ascending or descending
numerical order doesn't yield any particular order of the processes
that have those IDs. The only reasons for sorting would be aesthetic
ones, not functional ones.
| |
| Barry Margolin 2007-11-29, 7:21 pm |
| In article
<b52d3aab-9ac5-4abf-acef-5a1b738b30f5@b15g2000hsa.googlegroups.com>,
Benoit Lefebvre <benoit.lefebvre@gmail.com> wrote:
> On Nov 29, 8:54 am, K-mart Cashier <cdal...@gmail.com> wrote:
>
> for pid in "8 2 5 4 3 9 7 11"
> do
> kill $pid
> done
Why the for loop, rather than:
kill 8 2 5 4 3 9 7 11
--
Barry Margolin
Arlington, MA
| |
| Henry Townsend 2007-11-29, 7:21 pm |
| Barry Margolin wrote:
>
> Why the for loop, rather than:
>
> kill 8 2 5 4 3 9 7 11
Ironically, that's what the quotes end up doing.
HT
| |
| Kurt M. Weber 2007-11-29, 7:21 pm |
| J de Boyne Pollard wrote:
> JS> Guess the reason is that typically the parent processes have
> JS> lower PIDs and killing parents may take the children along
>
> But, conversely, killing the children first would often tend to cause
> the parents to exit of their own accord, if (for example) the parents
> were shells executing a command pipeline.
>
> Both of these are superficially attractive rationales. But they both
> break down. In reality, process IDs are not guaranteed to be created
> in _any_ order.
To add to that...even if you know that the particular system this will be
done on does indeed allocate PIDs sequentially, it still breaks down when
the maximum PID value is reached and they roll back over.
--
Kurt M. Weber
<kmw@armory.com>
| |
| Logan Shaw 2007-11-30, 1:47 am |
| J de Boyne Pollard wrote:
> JS> Guess the reason is that typically the parent processes have
> JS> lower PIDs and killing parents may take the children along
> But, conversely, killing the children first would often tend to cause
> the parents to exit of their own accord, if (for example) the parents
> were shells executing a command pipeline.
>
> Both of these are superficially attractive rationales. But they both
> break down. In reality, process IDs are not guaranteed to be created
> in _any_ order.
On the other hand, in a particular situation, it might be a given that
since you're going around killing processes in a wholesale fashion, you
are in a situation where there's already no way to guarantee you'll be
gracefully/correctly shutting down things. In that case, a heuristic
approach that increases the odds of not screwing too much stuff up[1]
might be helpful.
Sort of like typing "sync" and waiting 5 seconds before you unplug the
power cord rather than simply unplugging the power cord without a "sync".
Neither is correct and neither guarantees you anything, but if you have
to choose between the two, one is somewhat better than the other.
- Logan
[1] by taking advantage of the strong positive correlation between
the smaller-pid/larger-pid relationship and the parent/child
relationship that exists on many systems
|
|
|
|
|