From: toppi at kacke dot de Operating system: Fedora Core 2 Linux PHP version: 5.0.2 PHP Bug Type: *General Issues Bug description: shell doesnt close the connex after forking a process
Description: ------------ After forking a process and setting the child as sessionleader (becomes deamon) you cant disconnect from the current terminal-session (exit) solong the child is in process. After typing exit, the terminal prints the output from the child again. Youre always connected but no more control Current Config: [EMAIL PROTECTED] simon]$ php -v PHP 5.0.2 (cgi) (built: Oct 23 2004 14:07:24) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.2, Copyright (c) 1998-2004 Zend Technologies Reproduce code: --------------- #!/usr/local/bin/php -q <?PHP declare (ticks = 1); set_time_limit (0); ob_implicit_flush (); error_reporting(E_ALL); if( ($pid = pcntl_fork()) == -1 ) { echo "Error: Cant fork myself ! Dying.... \n"; } elseif($pid) { //PARENT PROCESS echo "Parent-Pid: ".getmypid()." quits here\n"; exit(0); } else { //CHILD PROCESS // detatch from the controlling terminal if (!posix_setsid()) { die("could not detach from terminal"); } //Install Signalhandler pcntl_signal(SIGTERM, "sig_handler"); pcntl_signal(SIGCHLD, SIG_IGN); $i=0; $childpid = getmypid(); //Do something for testing while ($i<20){ sleep(1); echo "Child-Pid $childpid ist working -> type exit to quit your shell-session ->it doesnt close the connex \n"; $i++; } echo "Just now we get diconnectet from the shell\n"; exit(0); } function sig_handler($signo) { switch($signo) { case SIGTERM: exit; case SIGCHLD: while( pcntl_waitpid(-1,$status,WNOHANG)>0 ) { } break; default: break; } } Expected result: ---------------- closing shell (telnet/ssh) and the child doing his background work Actual result: -------------- when starting ./testd.php (above) it looks 7360 simon 15 0 7308 2060 6856 S 0.0 0.2 0:00.00 sshd 7361 simon 25 0 4396 1340 3948 S 0.0 0.1 0:00.00 bash 7976 simon 16 0 10012 3452 8872 S 0.0 0.3 0:00.00 testd.php when "EXIT" the shell 7360 simon 15 0 7308 2060 6856 S 0.0 0.2 0:00.00 sshd <--- left solong the child repeats 20 times 7360 simon 15 0 7308 2060 6856 S 0.0 0.2 0:00.00 sshd when the child is done everthing got closed and the terminal is disconnected -- Edit bug report at http://bugs.php.net/?id=30539&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30539&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30539&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30539&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30539&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30539&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30539&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30539&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30539&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30539&r=support Expected behavior: http://bugs.php.net/fix.php?id=30539&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30539&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30539&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30539&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30539&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30539&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30539&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30539&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30539&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30539&r=mysqlcfg