Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Hello all - this is probably a easy question to answer, but I cannot seem to figure it out.

I need to launch a system process by a perl program (in my case, the program is called "root-tail") and get the Process ID for that program back so that I can save it to a file. Now, I am doing the fork()/exec() method:
die "Fork is bad: $!" unless defined ($pid = fork); if ($pid) { saveToFile($pid); } else { exec("root-tail","arg1","arg2"); }

Now, there are probably about ten arguments to "root-tail", and have them all just strung together in the exec() call, like above. However, when I save the PID to a file, and then go back and compare this PID with the PID of the process that is ACTUALLY RUNNING (via a call to 'ps'), the actual process id is always one higher: if my file that I saved to says 150, the actual pid is 151.

Does anyone know why this would happen? The perldoc's say that if there is a list of args to exec(), the shell will not be used at all, so why is there more than one process running, creating the one-up PID for my actual process?

Thanks for the help!

r. j o s e p h
"Violence is a last resort of the incompetent" - Salvor Hardin, Foundation by Issac Asimov

In reply to Exec() and getting system PID by r.joseph

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



  • 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.