php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50011 exec hangs on running self-daemonizing bash script
Submitted: 2009-10-27 07:53 UTC Modified: 2009-10-27 10:16 UTC
From: mathew at eisbox dot net Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.11 OS: Ubuntu
Private report: No CVE-ID: None
 [2009-10-27 07:53 UTC] mathew at eisbox dot net
Description:
------------
The attached bash script, when called via shell_exec, exec, and friends, reproducibly locks apache2 mpm and PHP. (Standard package from Ubuntu). ps shows a defunct sh process under apache2, and apache2 is unresponsive until the owning instance of apache2 is killed off.

When run from a shell, the script works without problems. (The script is meant to fork and detach, the detached process runs another process as a daemon)

This bug sounds similar to #44994, although this case is Linux, and closing the session does not solve the problem. So I opened a new bug.

Reproduce code:
---------------
# This is a simplified version of a script designed to reproduce the problem.
#!/bin/bash
DMNPATH=/path/to/dmn	# Path to dmn
DMNARGS="-arga -argb"	# Args to dmn
PIDFILE=/path/to/pid	# keepalive pidfile
# Setup the keepalive (must be a function to fork)
function rundmn {
	DMNPATH=$1
	DMNARGS=$2
	# Close stdin/stdout/stderr	  
	0<&-; 1>&-; 2>&-
	eval "$DMNPATH $DMNARGS"
}
# Check to see if we are already running
if [ -r $PIDFILE ] ; then
    kill -0 `cat $PIDFILE` > /dev/null 2>&1
    if [ $? -eq 0 ] ; then exit; fi
fi
# fork the rundmn func, save its PID, and detatch
rundmn "$DMNPATH" "$DMNARGS" &
PID=$!; echo $PID > $PIDFILE
disown $PID


Expected result:
----------------
I expect a call to exec to run the above bash script, which should return control almost immediately to the PHP script, continuing execution of the PHP script.

Actual result:
--------------
When run from PHP's exec, the bash script is behaving as expected, and executes to completion as expected. (I have verified execution to a point beyond the last disown command) However, no PHP code beyond the exec is run, and apache2 appears locked. I am uncertain how to proceed beyond this point.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-27 10:16 UTC] johannes@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You have to make sure to properly detach from the parent. When running from the shell your script will still be attached to the shell so PHP can finish.

See your system\'s nohup(1) manpage. Please ask further questions at a support place.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC