$ cat long.pl
#!/usr/bin/perl
use strict;
use warnings;
print localtime () . ": Hello from $0 ($$)!\n";
sleep 30;
print localtime () . ": Goodbye from $0 ($$)!\n";
__END__
$ cat fork.pl
#!/usr/bin/perl
use strict;
use warnings;
print localtime () . ": Hello from the parent ($$)!\n";
my $pid = fork;
die "Fork failed: $!" unless defined $pid;
unless ($pid) {
print localtime () . ": Hello from the child ($$)!\n";
exec "./long.pl"; # Some long running process.
die "Exec failed: $!\n";
}
print localtime () . ": Goodbye from the parent ($$)!\n";
__END__
$ ./fork.pl
Fri Mar 28 13:39:20 2003: Hello from the parent (458)!
Fri Mar 28 13:39:20 2003: Goodbye from the parent (458)!
Fri Mar 28 13:39:20 2003: Hello from the child (459)!
Fri Mar 28 13:39:20 2003: Hello from ./long.pl (459)!
Fri Mar 28 13:39:50 2003: Goodbye from ./long.pl (459)!
-
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.
|