On Fri, Nov 30, 2001 at 02:50:49AM -0600, Randy5235 wrote: > Pretty new to Perl still so forgive me a bit please. I have searched the web > (google is my friend) and searched the groups and found multiple things > concerning fork.
> here is the problem I can't find a page that has the basic > syntax for using it. fork() is one of the most basic operators when it comes to syntax; it's simply $pid = fork(), as hash been mentioned. I get the feeling you're not actually asking about syntax, but how and where to use it. For that, see perldoc perlipc for examples. fork() is pretty simple once you get to know it. After a fork call (provided it was successful) you have two processes. To determine what process you're currently in you examine fork()'s return value, $pid. If it's 0, you're in the child process. If it's a positive number you're in the parent process (the original process that called the fork). So: my $pid = fork(); die("Fork failed: \l$!.\n") unless defined($pid); if ($pid) { # do parent things, or do nothing } else { # do child things } So, for example, you need to check a password, and the current process handles the chat stuff in a loop. You'd use something like: my $pid = fork(); die("Fork failed: \l$!.\n") unless defined($pid); # or however you # report errors unless ($pid) { # check password exit; } You'd also probably want a $SIG{CHLD} handler to reap your children; read perlipc further, or ask more questions here. > If I understand this correctly if I fork the process then it will run at > the same time as the original process and everyone will be able to do > their thing?? is this correct? Well, technically, no, they will not run at the same time. However, they'll run at times close enough to each other that a human wouldn't be able to tell the difference. That is, assuming you don't have a multiple-processor system, where different threads can indeed run on different processors at the same time. Possibly. Anyways, as far as you're concerned (at the high-level programming area), yes, they do run at the same time. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]