[Gllug] Problems with getppid in Perl 5.8.x

Roy Drinkwater rdrinkwater at dial.pipex.com
Fri Feb 4 17:10:08 UTC 2005


Are there any Perl guru's out there who can help me with this one?  We have
an enormous amount of code with embedded getppid so a quick solution is
preferred.

The following perl module when invoked on perl 5.6.0 works fine, but with
perl 5.8.5 or 5.8.3 it never returns with 0 (i.e. hangs in the inner fork
because getppid always has the PID of the "half-way" child even after it has
died.

#!/usr/bin/perl5
#** Returns: zero to child process,
#**          non-zero to parent process.
package eg_fork;

sub main'eg_fork
{
	unless (fork)
	{
		unless (fork)
		{
			sleep 1 until getppid == 1;
			if (eval ("setpgrp"))
			{
				setpgrp;
			}
			close (STDOUT);
			close (STDERR);
			close (STDIN);
			return (0);	# Detached child process
		}
		exit (0);	# 'Half-way' child process
	}
	wait;
	return (1);	# Original parent process
}

1;

Answers gratefully received.

Roy Drinkwater

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list