[Melbourne-pm] Testing fork

David Dick david_dick at iprimus.com.au
Tue Aug 24 04:56:58 CDT 2004

Ok, test scripts are very nice, but some things are just ridiculously 
hard to do properly.

i've got a cgi-script that needs to accept a job from a user, return a 
202 and point the user to a url that they can use to monitor the job's 

Now, to kick off a job, the best way that i can think of is to partially 
daemonize (i don't want to close STDERR for example) and run the job in 
the partial daemon, while the original cgi process returns the pointer 
to the user.

Unfortunately, the following bit of code has some issues;

	if ($pid = fork) {
		exit 0;
	} elsif (defined $pid) {
	} elsif ($! =~ /No more process/) {
		sleep 5;
		redo FORK;
	} else {
		die("Can't fork:$!");

1) How on earth can i test the /No more process/ line?  I think i need a 
"ulimit -u" sort of capability, and need to switch it on and off to get 
the code to enter and exit the condition.

2) The horrifying mutations that this code can be subjected to.  For 
example, i'm writing the code as a cgi script to maximise portability. 
For speed, the code be run using Apache::Registry.  Which, among other 
things silently overrides the exit statement, unless you fully qualify 
as CORE::exit.  I'm damned if i know how, even if i know and expect the 
weird environmental conditions, that i can test that my code is correct 
in an environment such as Apache::Registry;

3) probably a whole lot of other issues that i'm not aware of yet.

anyone got any ideas on writing a test script for these sort of issues?

More information about the Melbourne-pm mailing list