baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
after surfing the net for a while in quest for solution a need i came with an answer that it cannot be done. so i figured there must be someone here that thinks differently. the problem is , i am running a perl application that forks itself after a while. when forked the outside process is called and set to run on a different machine through ssh. ok so complications emerge when a user is trying to kill the process (perl application) by issuing a Ctrl-C. so what happens is the main application and its children are killed indeed but since the outside process is getting a new PID when started i have no control over it , meaning i can't automatically kill it (have to do it manually one by one)
i thought of ps-ing every machine and retrieving the PID by process name but then it hit me what if two users started the same outside aplication and one is trying to kill it and the other one is not. in that case my subroutine will identify all outside PID's by process name and kill them all (not the ones started by me)
so my question is (i went through CPAN - 0 points)did anyone encountered this problem and did he/she found the solution.
the solution probably lies in the catching the PID of a process right when the process starts so something like when i start the appl.
i should automatically catch the ID of the process into some variable to be dealt with latter. the grid engines have this problem resolved but i can't seam to figure out where the answer lies.$PID = system('./myAPP'); # I'm aware this is something that does not +exist
thank you
example:
my @children; for (my $i = 1;$i<=5;$i++){ my $pid = fork(); if ($pid){ push @children, $pid; } elsif ($pid == 0){ system("ssh $mch aplication"); exit; } else{ die "could not fork! \n"; } } foreach (@children){ waitpid($_,0); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to kill deattached process
by Corion (Patriarch) on Oct 31, 2009 at 15:30 UTC | |
|
Re: how to kill deattached process
by BioLion (Curate) on Oct 31, 2009 at 15:39 UTC | |
|
Re: how to kill deattached process
by salva (Canon) on Oct 31, 2009 at 17:08 UTC | |
|
Re: how to kill deattached process
by jethro (Monsignor) on Oct 31, 2009 at 15:35 UTC | |
|
Re: how to kill deattached process
by zentara (Cardinal) on Nov 01, 2009 at 15:02 UTC | |
|
Re: how to kill deattached process
by baxy77bax (Deacon) on Nov 01, 2009 at 13:13 UTC | |
by salva (Canon) on Nov 01, 2009 at 14:20 UTC |