avik1612 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: kill a process
by zentara (Cardinal) on Jul 03, 2007 at 13:38 UTC
    Without more details, you may need to kill the parent process. Often, when you fork off a process, the $pid return is actually the bash shell (usually :-) ) , and your actual program is spawned from that. It can get tricky to know exactly which pid you are talking about. See "perldoc Proc::Killfam"..... and here is a manual way.

    You need to give more info on how you are creating the process, so we can tell if a shell gets involved, and you thus have a parent process.

    #!/usr/bin/perl use warnings; use strict; #robau #This subroutine takes two arguments, the parent process ID #and the numeric signal to pass to the processes #(which would be 9 if you wanted to issue a -TERM). #Using Proc::Process you could find the process ID #of the process login -- zentara with something similar #to the following : #my $proc = Proc::ProcessTable->new; #my @ps = map { $_->pid if ($_->cmndline =~ /login -- zentara/) } @{$p +roc->table}; #&killchd($_, 9) foreach @ps; &killchd(9895, 9); #kill -9 process 9895 sub killchd ($;$) { use Proc::ProcessTable; my $sig = ($_[1] =~ /^\-?\d+$/) ? $_[1] : 0; my $proc = Proc::ProcessTable->new; my %fields = map { $_ => 1 } $proc->fields; return undef unless exists $fields{'ppid'}; foreach (@{$proc->table}) { kill $sig, $_->pid if ($_->ppid == $_[0]); }; kill $sig, $_[0]; };

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: kill a process
by archfool (Monk) on Jul 03, 2007 at 12:58 UTC
    You will need to give us a LOT more information in order to be able to help you.

    What OS? What process are you trying to kill? By PID? By process name? By user name?

    What are "Various conditions"? Which user?

Re: kill a process
by moritz (Cardinal) on Jul 03, 2007 at 13:18 UTC
    That is possible, since Perl is turing complete and can kill processes. Any Questions?

      "What's the average airspeed velocity of an unladen swallow?"

      Oop, wait . . . let me Winnify that . . .

      "What's the average airspeed velocity of an unladen swallow? I'm trying to find this with Perl."

      Perhaps more germane: Should the OP have read How (Not) To Ask A Question? (I think yes)

Re: kill a process
by shmem (Chancellor) on Jul 03, 2007 at 14:18 UTC
    perl script to kill a process under various conditions by the user
    insert money in slot, come back with receipt.

    See How (Not) To Ask A Question (do your own work).

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}