Re: How do I end processes that time out?
From: J. Romano (jl_post_at_hotmail.com)
Date: 07/23/04
- Next message: Ilmari Karonen: "Re: Needs help with Matching Logic"
- Previous message: Robin Corcoran: "Re: Use a variable value in another variable's name"
- In reply to: Ilmari Karonen: "Re: How do I end processes that time out?"
- Next in thread: Ilmari Karonen: "Re: How do I end processes that time out?"
- Reply: Ilmari Karonen: "Re: How do I end processes that time out?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Jul 2004 23:13:00 -0700
> On 2004-07-19, J. Romano <jl_post@hotmail.com> wrote:
> >
> > I finally got it to work by not killing the child's $pid
> > (process id), but $pid + 1. For some reason, the pid
> > assigned to the child process by the OS was one more than
> > what was returned from the open() statement. Would anyone
> > know why?
Ilmari Karonen <usenet@vyznev.invalid> replied in message
news:<slrncfo8pm.14p.usenet@yhteiskone.vyznev.net>...
>
> Presumably because perl hands the command to a shell for parsing. The
> $pid you get is for the shell, not for the actual command executed.
> For some reason, killing the shell has different effects on different
> platforms.
>
> (The reason why killing $pid+1 appears to work is simply that process
> id numbers are often assigned sequentially, so the pid of the actual
> command often just happens to be one greater than that of the shell.)
Your explanation makes sense, Ilmari. So I would think that
killing $pid+1 will usually work in my case, but won't work 100% of
the time (and therefore should not be relied on).
> You can avoid this by using the list form of open(). Simply replace
>
> "perl -e '$tinyProgram'"
>
> in your example code with
>
> "perl", "-e", $tinyProgram
>
> and everything should work as expected.
Oddly enough, that doesn't work for me. When I use the line:
my $pid = open(CHILD, '-|', 'perl', '-e', $tinyProgram);
I get the following fatal error message at run-time:
Can't use an undefined value as filehandle reference ...
This happens even with the following line:
my $pid = open(CHILD, '-|', 'ls', '-l');
but doesn't happen when I use the one-argument form of "ls", like
this:
my $pid = open(CHILD, '-|', 'ls');
I can't figure out why it's giving me an error message, because
according to "perldoc -f open", the following four lines should be
more or less equivalent:
open(FOO, "cat -n '$file'|");
open(FOO, '-|', "cat -n '$file'");
open(FOO, '-|') || exec 'cat', '-n', $file;
open(FOO, '-|', "cat", '-n', $file);
so if the line:
my $pid = open(CHILD, '-|', "perl -e' $tinyProgram");
works, likewise the line:
my $pid = open(CHILD, '-|', 'perl', '-e', $tinyProgram);
should also work, just as you said it would. But it doesn't. I keep
getting the fatal run-time error message that I can't use an undefined
value as a filehandle reference when I use the list form of open().
Am I missing something?
(Just so you know, this same error happens on two separate Unix
machines. Their "perl -v" output is:
This is perl, v5.6.1 built for alpha-netbsd
This is perl, v5.6.1 built for i386-linux
)
I did get around this error, however. I used the third form of the
open() statements listed above (the one with the exec() call).
Therefore, I replaced the line:
my $pid = open(CHILD, '-|', "perl -e' $tinyProgram");
with:
my $pid = open(CHILD, '-|') || exec 'perl', '-e', $tinyProgram;
and everything worked correctly (meaning that I also received the
correct $pid used to kill the process).
So in the end, I solved my problem of killing child processes that
time out, but now I don't understand why the list form of open() keeps
giving me a fatal error message. If anyone knows why, please let me
know.
Anyway, thanks for all your help. I appreaciate it.
-- Jean-Luc
- Next message: Ilmari Karonen: "Re: Needs help with Matching Logic"
- Previous message: Robin Corcoran: "Re: Use a variable value in another variable's name"
- In reply to: Ilmari Karonen: "Re: How do I end processes that time out?"
- Next in thread: Ilmari Karonen: "Re: How do I end processes that time out?"
- Reply: Ilmari Karonen: "Re: How do I end processes that time out?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|