I usually like to stuff the pids of processes, into an array or hash. as I create them, for easy killing later

You can, as you suggest, give the forked process, a unique name, and kill the process later by searching for the pid of the name

#!/usr/bin/perl -w use strict; use Proc::ProcessTable; my $t1 = new Proc::ProcessTable; my $pid; my $commandline = shift || $0; foreach my $p (@{$t1->table}){ if($p->cmndline =~ /\Q$commandline\E/){ $pid = $p->pid; print "$pid\n"; } } ###################################################

The one thing to watch out for, is quite often, you get the pid of a shell (like bash or sh) which runs your external process... so you often need to kill the pid and all it's children, to get the whole shebang killed.

...this may be useful, as a guide

#!/usr/bin/perl -w use strict; use Proc::ProcessTable; #-- #-- we will ignore the child #-- $SIG{CHLD} = 'IGNORE'; #-- #-- create 5 child processes for demo purpose. arrange them so they st +ay #-- long enough so we can find them later #-- for(1..5){ sleep(10) and exit if(fork == 0); } #-- #-- list all process running in your machine and find all #-- child process #-- for my $p (@{new Proc::ProcessTable->table}){ print $p->pid," child of $$\n" if($p->ppid == $$); }
also look at rsync with tk progressbar for some ideas for tracking down child processes

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

In reply to Re: how to kill deattached process by zentara
in thread how to kill deattached process by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.