My question is, is this expected (and why?) and/or is this behavior seen on other systems too?
Environment:
# cat /etc/*-release
CentOS release 6.6 (Final)
...
# perl -v
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
...
# php -v
PHP 5.4.41 (cli) (built: May 14 2015 23:15:28)
...
mini.pl:
#!/usr/bin/perl
exec('/usr/bin/php -v');
Run it and see the hung PHP process:
# perl mini.pl &
[2] 16958
[1] Killed perl mini.pl
# ps ax | grep 16958
16958 pts/2 T 0:00 /usr/bin/php -v
16960 pts/2 S+ 0:00 grep 16958
[2]+ Stopped perl mini.pl
But if I close STDIN:
mini.pl:
#!/usr/bin/perl
close(STDIN);
exec('/usr/bin/php -v');
It runs fine:
# perl mini.pl &
[1] 16976
# PHP 5.4.41 (cli) (built: May 14 2015 23:15:28)
...
[1]+ Done perl mini.pl
# ps ax | grep 16976
16978 pts/2 S+ 0:00 grep 16976
Other notes:
Thanks,
stdin − It stands for standard input, and is used for taking text as an input. stdout − It stands for standard output, and is used to text output of any command you type in the terminal, and then that output is stored in the stdout stream.
Use bg to Send Running Commands to the Background You can easily send such commands to the background by hitting the Ctrl + Z keys and then using the bg command. Hitting Ctrl + Z stops the running process, and bg takes it to the background. You can view a list of all background tasks by typing jobs in the terminal.
nohup is a POSIX command which means "no hang up". Its purpose is to execute a command such that it ignores the HUP (hangup) signal and therefore does not stop when the user logs out.
I just tested this on Ubuntu 14.04 and RHEL 6.7, and could not reproduce the problem.
I suspect there is a bug that is causing it to both print the version and attempt to process STDIN as PHP code. While it's hanging, try pressing Control-D, or typing a few lines of HTML/PHP and then pressing Control-D to see if your input is processed.
I have a CentOS with the same issue, resolved by adding an ampersand(&) at the end of the system call while you can keep yum.
I actually use a python script to call the php, same issue.
The real issue - unknown, if anyone have some idea, please let me know as well.
Solution:
exec("/usr/bin/php -v &");
`/usr/bin/php -q ./mini.php &`;
my os:
CentOS release 6.4 (Final)
CentOS release 6.4 (Final)
[gliang@www perl_tools]$ perl -v
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
[gliang@www perl_tools]$ php -v
PHP 5.3.3 (cli) (built: Jul 9 2015 17:39:00)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.4, Copyright (c) 2002-2012, by Derick Rethans
[gliang@www perl_tools]$
Issue duplicated:
[gliang@www perl_tools]$ perl mini.pl &
[1] 29744
[gliang@www perl_tools]$ ps uax|grep php
gliang 29744 0.1 0.3 341016 8728 pts/0 T 20:27 0:00 /usr/bin/php -v
gliang 29756 0.0 0.0 103248 812 pts/0 S+ 20:27 0:00 grep php
[1]+ Stopped perl mini.pl
[gliang@www perl_tools]$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With