krups Posted August 24, 2006 Share Posted August 24, 2006 exec(), system(), passthru(), shell_exec(). These commands when executed always left a defunct process. Then when I reconfigured php with --enable-sigchild option it was better as now it does not leave a defunct process always..... but mosttimes we still get defunct process. I wrote code to kill defunct process. The code executes correctly. The defunct process also gets killed but later the page is not displayed. Looks like php hangs.exec("/bin/kill -9 $ppid";system("/bin/kill -9 $ppid /dev/null/ 2>&1 &");passthru(kill -9 $ppid &);shell_exec(bin/kill -9 $ppid &);Also tried posix_kill($ppid, 1); where $ppid is parent process id. Is there any conifuration options that I should use or any php.ini parameters that I should change. Please help me with this query. We are using PHP with apache. The configure option is as mentioned below.'./configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-mm=/usr/local' '--enable-sigchild' '--enable-force-cgi-redirect' '--enable-discard-path' '--enable-fastcgi' '--enable-pcntl' '--enable-posix' Quote Link to comment Share on other sites More sharing options...
drkstr Posted August 25, 2006 Share Posted August 25, 2006 What user.group is apache running under? Are the processes you're running sudo'ed as another user? Did you do anything special to give apache's user permissions to execute the processes?Just a guess, but maybe you don't have permission to kill the proccess? Try doing some testing to see if it's the same processes that get hung up, or if it's random.You might want to also consider using popen instead. This is what I used to call sfdisk, and it allows you to grap output/errors.Example[code]$ph = popen( "sudo /usr/sbin/sfdisk -l | grep dev", "r" );$arOutput = explode( "\n", fread($ph, 4096) ); #break string into an array of linespclose($ph);[/code]regards,...drkstr Quote Link to comment Share on other sites More sharing options...
krups Posted August 28, 2006 Author Share Posted August 28, 2006 Thanks for your response. apache is running as user "nobody" and the application called inside exec(), which leaves a defunct process is another user "root". I cannot run apache as root. So what is the best thing to do? Quote Link to comment Share on other sites More sharing options...
drkstr Posted August 29, 2006 Share Posted August 29, 2006 1. If the application you're running does not require root privileges, run it as user "nobody" by calling it with 'sudo -u nobody your_application'.or2. Use the "kill" method you mentioned earlier, except call it with 'sudo kill your_application'. This will require you to add user "nobody" to your /etc/sudoers file to enable that user to run the kill command as root without needing to supply a password.Just out of curiosity, how did you run the application as root to begin with? Did you do it with sudo, or is this a "feature" (bug) of PHP? When I run a command with popen, it runs as the user that apache runs under.regards,...drkstr Quote Link to comment Share on other sites More sharing options...
krups Posted August 29, 2006 Author Share Posted August 29, 2006 Sorry my mistake this application if we bring it up manually it runs as root and does not leave any defunct process behind.But when we run it through PHP GUI it runs as user nobody. Actually we have 2 applications running one (C++) Test application which we start manually as user "root" on command line then through the PHP GUI we call another application(one which is leaving a defunct process), this application talks to our test application, sends message to the test application and changes certain configuration parameters of the test application while the test application is running. The PHP gui is nothing but a web interface of the application which talks to the test application.Can I run the application as user root through php by using 'sudo' instead of user nobody? I have not used sudo before.... Thanks,Krups Quote Link to comment Share on other sites More sharing options...
drkstr Posted August 29, 2006 Share Posted August 29, 2006 You don't want to execute *any* programs if you don't have to. If the gui front end app is communicating fine with the test app, leave it the way it is.As far as the defunct process goes, can you describe exactly what you mean by this? Give details on what specificly you're experiencing. Is PHP hanging, is it running fine but not killing the process when you close PHP? also give the exact code you're using to start and stop the process....drkstr Quote Link to comment Share on other sites More sharing options...
krups Posted September 1, 2006 Author Share Posted September 1, 2006 Thanks a lot for your reply.The PHP GUI cannot directly talk to the test application. We have another executable (Console- executes MML commands) this Console application can talk to the test application.So in the PHP GUI what we do is pass a command to the console application. This command brings up the application, excutes the command and after executing the command the console application exits and is closed down. PHP successfully brings up the console application, executes the command and then also the console application is closed. PHP does not hang here but there is a defunct process left of the console application. We need to run this console application. PHP GUI is like a web interface to the console application. Both the test application and console application are written in C++. If we manually bring up test application (as root) and also console application (as root) and execute the same commands that we would through PHP GUI then there is no defunct process left. Everytime we click the PHP GUI it calls the console application as mentioned above.Only problem is we do not want to see a whole list of defunct processes after each click on the GUI. What would be the best way to avoid the defunct process. After we added --enable-sigchild' to configure command in PHP we do not get defunct process after every time we click the PHP GUI. But we still get defunct process a lot of times.... what's different is that the defunct process might also eventually go away if the parent process id is still there.... I mean a lot of child process id's are present for the same parent process id. Then if we click on the GUI then the defunct processes are gone. But if we do not click the GUI for a while and there is now a new parent process id then old defunct processes stay. PHP does not hang when we call the console application. I was trying to write code to kill all existing defunct processes using "kill -9 ppid" this time PHP hangs.... But if we can avoid getting defunct processes then we do not need to kill any process. The configure option is as mentioned below.'./configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-mm=/usr/local' '--enable-sigchild' '--enable-force-cgi-redirect' '--enable-discard-path' '--enable-fastcgi' '--enable-pcntl' '--enable-posix' Code after which php will leave a defunct process. Note PHP does not hang here it executes successfully but leaves a defunct process.$command="dbc/Console -socket spc_disp_config 1";exec($command,$status,$dresult);Thanks,Krups Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.