2

x.php:

<?php
sleep(15);
?>

console:

$ php x.php &
[1] 5742
[1]+  Stopped                 x.php

Result: a "STOPPED" process - it's there forever until I send a TERM and then CONT signal.

What I need instead: the process to finish and quit after 15 seconds, so I don't see it in top or htop.

System: Ubuntu 12.04 LTS in VirtualBox; php-fpm

  • Actually it is not about "how to code something", but about "how to run my script in background", which looks more like a question related to "power users", as stated in the website's Tour. Re: what you are trying to do - that's described in the "What I need instead" paragraph. – Meglio Jan 8 '14 at 19:09
  • 1
    Is there more to X.php, or did you just forget to close your PHP tag in the example? – Ƭᴇcʜιᴇ007 Jan 8 '14 at 19:19
  • Nothing else in x.php file (it's allowed and recommended to omit closing tag). Fixed my question to avoid confusion. – Meglio Jan 8 '14 at 19:40
  • Why would you want to do this? It would be easier to just run sleep 15 instead of php. – Kevin Panko Jan 8 '14 at 22:31
  • @KevinPanko The PHP script is just a minimal example used for simplified testing and posting to this website - it was used in replacement of the real workhorse-script. – Meglio Jan 9 '14 at 1:44
4

Using strace I see that the program is getting a signal SIGTTOU which means the process was in the background and attempted to write to the terminal, or in this case, change one of its modes.

ioctl(0, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B38400 opost isig icanon echo ...}) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGTTOU {si_signo=SIGTTOU, si_code=SI_KERNEL} ---
--- stopped by SIGTTOU ---

To get around this, set the input to null:

$ php x.php < /dev/null &

The question is the same as this one: PHP script won't run in the background

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.