Jason Frisvold <[EMAIL PROTECTED]> wrote:
> I'm writing a monitoring system (Yes, still... Finally got the
> go-ahead to do this) and my design calls for a central "Smart"
> Daemon that spawns and monitors the lesser Daemons that do the
> actual monitoring. My problem is that I'm not sure how to go
> about this.
>
> From what I understand, fork actually creates a duplicate (clone)
> of the current program and runs it. Based on the pid, you can
> determine if you're the parent or the child. I may be able to use
> this, but it won't allow me to spawn the seperate processes that
> need to run.
>
> System spawns the process but blocks and waits for a return?
> Great, but I need to spawn, get the pid, and monitor on my own
> and not via a system call...
>
> Exec spawns and runs this new program, forgetting the old one...
> In essence, the old one ceases to run ... (I think ... feel free
> to correct me)
That's all more or less correct, but you're missing a fundamental
point: fork() and exec() are used *together* to run the external
program.
#
# 1. create a new process with fork()
#
defined (my $pid = fork)
or die "couldn't fork: $!";
#
# 2. run "something else" with exec()
#
if ($pid == 0) {
exec $cmd, @args;
die "couldn't exec '$cmd': $!";
}
Since the exec() only happens in the child, the parent keeps
running the Perl script.
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]