Just to clarify what AM said above: because you are using both redirection and backgrounding in the string passed to "exec", a shell process has to be launched to execute that command line, and the shell exits. If you don't background it, the shell will keep running for as long as the sleep, and your " ps ax | grep sleep" step will show three lines of output - the additional line would be the shell process that is running "sleep 30".
Apart from that, you should be aware that the "exit" statement in your "if" block is never reached -- as stated in the perlfunc manpage, the "exec" call never returns.
If you remove both backgrounding and redirection from the command line string, your parent perl process will get the pid for the child sleep process, because "exec" won't have to invoke a shell to run the command -- i.e. you could do either this:
exec( "sleep 30" );
or this:
exec( "sleep", "30" );
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|