Re: killking child processes
From: Irek (ireneusz.szczesniak_at_wp.pl)
Date: 06/20/05
- Previous message: T.M. Sommers: "Re: IPs of local interface"
- In reply to: Michael Kerrisk: "Re: killking child processes"
- Next in thread: David Schwartz: "Re: killking child processes"
- Reply: David Schwartz: "Re: killking child processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 Jun 2005 10:23:01 -0700
Thanks for your reply, Michael.
> Perhaps it would help if you paint a slightly bigger pigcture of what
> you want to do, and why.
I am developing a client-server application. The client is written in
Java and connects to a remote computer with ssh. At the remote
computer the connection is accepted by the ssh daemon, which starts for
us an application that is the server.
The client issues some commands to the server, so it's a kind of a
login session. However, other clients can connect later to the same
server. The server is supposed to die when the last client
disconnects. The last client to disconnect doesn't have to be the
client which started the server.
The server creates some children to help perform the offered services.
When the server dies I want to make sure that the children die too. I
do not want the users to log in to the remote computer just to kill the
running processes.
> So, is your main program running arbitrary programs in it's children?
They are not arbitrary. These programs are some commands, but I know
in advance what they are.
> If it is, then you probably have no definitive guarantees about being
> able to kill them. You already identify one of them (leaving the
> process group) that affects your solution.
I understand that programs are albe to run away from my control. They
can fork so that PID changes: the parent exits, the child keeps running
under a different PID. They can change the process group, they can
change their session. I understand these actions, and so I make sure
that the children which the server spawns don't change their process
group.
> I assume here that you mean that the signal handler does the
> kill(-pgrp, SIGTERM)?
Yes, I do kill(0, SIGTERM).
>> Every child process spawned by the main process will receive SIGTERM,
>> unless the child process leaves the process group of the main process.
>
> And what do you think to do in that case? What I'm really meaning is:
> you seem not to care too much about this case -- or do you? If you
> don't really care about this case, why not?
I know what the children do. Before I decide to incorporate some
command into the server, I make sure that this command will not change
its process group. Therefore I do not have to worry how to kill the
processes which changed their process group.
> And what if one of the programs you run is set-user-ID-root, and
> changes its credentials in such a way that you can no longer kill it
> (i.e., changes both its real and saved set-user-ID)?
>
> And what if the child programs make themselves immune to (i.e., ignore
> or catch) SIGTERM?
Yes, these are problems which I should consider if I ran arbitrary
commands. However, I know that the commands which I use will not pose
such problems.
> I don't suppose that this solution is really any more reliable. What
> if your STOPPED child is killed for some reason?
I agree that the STOPPED child may be killed and then my whole scheme
is for nothing. But this is a "safety system." If the main process
dies before it gets to killing the child processes, there would be
still some chance for killing the child processes. Indeed there is
this chance because this STOPPED process might have not been killed,
and it will take over the task of killing the children.
Thanks again, Michael, for your detailed e-mail. I trully appreciate
it.
Best,
Irek
- Previous message: T.M. Sommers: "Re: IPs of local interface"
- In reply to: Michael Kerrisk: "Re: killking child processes"
- Next in thread: David Schwartz: "Re: killking child processes"
- Reply: David Schwartz: "Re: killking child processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|