[Sussex] the who/what/why/when of processes ( proc-i ? ;)

dunk fordyce him at dunkfordyce.co.uk
Thu Sep 5 11:48:00 UTC 2002


( /me thinks this will be a contest between geoff and steve - first reply gets the unbranded, highly polished car )

unix processes.

ive done very little with processes - and only in a C world.
at the moment im looking at *chuckle* php process control, which luckily looks just like C ones.

here's there example

<?php

$pid = pcntl_fork();
if ($pid == -1) {
     die("could not fork"); 
} else if ($pid) {
     exit(); // we are the parent 
} else {
     // we are the child
}

// detatch from the controlling terminal
if (!posix_setsid()) {
    die("could not detach from terminal");
}

// setup signal handlers
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");

// loop forever performing tasks
while(1) {

    // do something interesting here

}

function sig_handler($signo) {

     switch($signo) {
         case SIGTERM:
             // handle shutdown tasks
             exit;
             break;
         case SIGHUP:
             // handle restart tasks
             break;
         default:
             // handle all other signals
     }

}

?>

now... 

the bit i dont understand is the first if statement ( doing well so far ey? )

not being able to think how to phrase my questions, ill put it in some sort of context.

if i wanted to start an irc bot that spawned a new proccess for each room it was in, how would that work? also if i then wanted to have a new proccess to do something completely different, like search the web, how would that go?

gladly point me at references or what ever. no need to be php specific of course :) 




More information about the Sussex mailing list