Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl Threads - Capture Exit
    primarykey
    data
    text
    <p>I have code that spawns two threads. The first is a system command which launches an application. The second monitors the program. I'm new to perl threads so I have a few questions...</p> <pre><code>my $thr1 = threads-&gt;new(system($cmd)); sleep(FIVEMINUTES); my $thr2 = threads-&gt;new(\&amp;check); my $rth1 = $thr1-&gt;join(); my $rth2 = $thr2-&gt;join(); </code></pre> <p>1) Do I need a second thread to monitor the program? You can think of my sub routine call to &amp;check as a infinite while loop which checks a text file for stuff the application produces. Could I just do this:</p> <pre><code>my $thr1 = threads-&gt;new(system($cmd)); sleep(FIVEMINUTES); &amp;check; </code></pre> <p>2) I'm trying to figure out what my parent is doing after I run this code. So after I launch line 1 it will spawn that new thread, sleep, then spawn that second thread and then sit at that first join and wait. It will not execute the rest of my code until it joins at that first join. Is this correct or am I wrong? If I am wrong, then how does it work?</p> <p>3) My first thread the one that launches the application can be killed unexpectedly. when this happens, I have nothing to catch that and kill the threads. It just says: "Thread 1 terminated abnormally: Undefined subroutine &amp;main::65280 called at myScript.pl line 109." and then hangs there.</p> <p>What could I do to get it to end the other threads? I need it to send an email before the program ends as well which I can do by just calling &amp;email (another subroutine I made).</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload