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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.