Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the PHP code, I have the following:

run.php

<?php
shell_exec("php theprocess.php > /dev/null 2>&1 &");
?>

I execute run.php from the browser (eg: http://localhost/run.php)

Then I typed: ps ux

username [~/www/site/test]# ps ux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
username   847  0.0  0.1  23808  7724 ?        R    16:55   0:00 php theprocess.php
username   849  0.0  1.2  89504 53244 ?        R    16:55   0:00 php theprocess.php
username   851  0.0  0.7  89504 31592 ?        R    16:55   0:00 php theprocess.php
username   853  0.0  0.1  23628  4636 ?        R    16:55   0:00 php theprocess.php
username   854  0.0  0.0   2276   824 ?        R+   16:55   0:00 ps ux
username  3880  0.0  0.0  10080  1704 ?        S    16:33   0:00 sshd: username@pts/2
username  3883  0.0  0.0   2676  1368 ?        S    16:33   0:00 -jailshell

I dont understand why is it showing more than 1 theprocess.php process? I have only executed 1 time. I did not execute more than 1.

Edit:

Also why it still running at the background? it should terminate theprocess.php finish the task.

share|improve this question
    
I'd suspect "shell_exec" itself is key.. – Doc Jul 7 '11 at 17:22
    
see answer .... – user79590 Jul 7 '11 at 22:36

I have fixed the problem!

When running script from a browser, it does not treat as PHP cli.

Replace

shell_exec("/usr/bin/php theprocess.php > /dev/null 2>&1 &");

To

shell_exec("/usr/bin/php-cli theprocess.php > /dev/null 2>&1 &");

I no longer have multiple procress running in the background.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .