Langa Kentane wrote:

> Greetings,
> I wish to use the fork() function on one of my scripts. I would like more
> clarity on the way it works.
>
> Take for instance the ff code:
>
> Sub mysub
> {
>         while (<THATFILE>)
>         If ($_ eq "SCANME")
>         {
>                 fork()

After the fork call the child continues execution from that point on. In this case the 
parent
and the child will do the system call and print forked. The right way to do this woul 
be
my $pid = fork();
if ($pid == 0) {
  print "pid returned to the child is $pid\n";
  print "child's pid is $$\n";
} else {
  print "pid of the child is $pid\n";
}

fork() returns 0 to the child process and the child's pid to the parent.
For info on $$ (perldoc perlvar)

>
>                 system("nessus" "thathost");
>                 print "Forked!\n";
>         }
>         Else
>         {
>                 fork()
>                 system("nmap", "-sS", "-T", "insane", "mynetwork")
>                 print "Forked on else\n";
>         }
>         close THATFILE;
> }
>
> What I would like to know when I do the fork on the if statement, does the
> child just do the stuff under if block & exit??
> What happens exactly? Is this the right way of doing this?
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to