The steps for the script are as below:
1. Fork the main process into Child & Parent processes.
2. Child (PID ==0) will do some processing (testing that can be conformance or use case anything)
3. Meanwhile parent will run a timer that will have a count set at starting of script
4. If the child process completes before the final count then we have to stop the timer that runs on the parent process
5. If the Child process does not complete before the count (i.e in case the child process hangs) then the parent process will kill the child process.
I don’t have any problem executing step 5. That works totally fine.

The only problem is to execute step 4 that I’m not able to stop the timer on parent process if the child process completes before timer reaches its final count. The parent has to stop the timer if the child process ends before the timer reaches final count.

if (!defined($kidpid = fork())){ # fork returned undef, so failed die "cannot fork: $!"; }elsif ($kidpid == 0) { # fork returned 0, so this branch is the child $TestResult = &$TEST_PROCESS($_[0], $_[1]); # &$TEST_PROCESS is a subroutine that is written in some other file th +at will return 1 if success exit; # terminate the child thread... } else { for ($timer=0;$timer<=$TEST_TIMEOUT;$timer++) {


Here I want to check the status of the child process .i.e. if it is running or not. If the child process does not end before $TEST_TIMEOUT(defined in another script) I want to kill the child process.

The only problem I face is how to check the status of the child process.

Can i share a varible between the child & parent process that will get updated when the child process completes?
} }

Edited by planetscape - fixed code tags


In reply to is sharing variables between forked process possible?? by sagar_kempe

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.