Re: Detect Process End
by brian_d_foy (Abbot) on Nov 27, 2004 at 05:38 UTC
|
If you know the process ID, use the built-in kill() command with the 0 signal.
while( kill( 0, $pid ) ) { ... }
Or did you already try that? What's your process doing after you try to kill it?
--
brian d foy <bdfoy@cpan.org>
| [reply] [d/l] |
|
|
| [reply] |
|
|
What is kill 0 (instead of kill 15)???
| [reply] |
|
|
Re: Detect Process End
by ikegami (Patriarch) on Nov 27, 2004 at 05:07 UTC
|
system "/bin/ps -p $a" does not return a true when the process is still running
Specifically, system doesn't return at all while the child process is still running. Also, it doesn't provide the output in a variable, which I think you want. Try open(HANDLE, "/bin/ps -p $a |") if you wish to get the info as ps prints it, or use backticks ($info = `/bin/ps -p $a`) if you just want the output when ps is done running.
| [reply] [d/l] [select] |
|
|
Please excuse my ignorance, I am really a beginner at this.
I don't really want any output at all. I don't want any information back from ps. I just want to get a "true" if the process is still running.
TNX if you can get me over this hump.
| [reply] |
|
|
Here is a simpler explanation of
ikegami(++)'s post:
What you are trying to do is to keep running "ps -p $a" until you get a null output.
In order to do that, you need to look at the output of that command.
The "system" command does NOT provide the output.
The backticks ($info = `/bin/ps -p $a`) DO provide that, capturing the output into $info.
You then need to look for a null $info.
...each is assigned
his own private delusion but he cannot see the baggage on his own
back.
| [reply] |
|
|
Re: Detect Process End
by Zaxo (Archbishop) on Nov 27, 2004 at 08:10 UTC
|
You've got good advice above, here are a couple more possibilities.
You can set up a $SIG{CHLD} handler to respond to a child process's exit, whatever the reason for it. If it's ok to sleep for a bit after some processing, waitpid will do that.
| [reply] |
Re: Detect Process End
by QM (Parson) on Nov 27, 2004 at 17:45 UTC
|
I posted some code here that demonstrates how to wait for child processes. That root node may give you some other ideas and places to look too.
If your question is not about child processes, you may want to dig into IPC and interprocess signalling.
-QM
--
Quantum Mechanics: The dreams stuff is made of
| [reply] |
Re: Detect Process End
by Anonymous Monk on Nov 27, 2004 at 13:42 UTC
|
I'm going to assume (bad idea, I know) that you're wanting to run this on linux. As such, linux stores process information in /proc/<pid>/. You could simply stat() the directory. If it exists, the process is running. If it fails, the process has ended. | [reply] |
|
|
FYI -- other os's have the same or similar services. I know Solaris also has a /proc file system that can be used in the same way.
--DrWhy
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
| [reply] |
Re: Detect Process End
by geektron (Curate) on Nov 30, 2004 at 01:34 UTC
|
| [reply] [d/l] |