exec() keeps executing the command Again and Again like an infinite loop, despite of No loop in the program

こ雲淡風輕ζ 提交于 2020-01-03 04:35:44

问题


ADDENDUM: The problem in the question below is due to the SECOND command. When I comment out the second statement, the first one runs as expected and produces expected results. :s


I needed to run two terminal commands from PHP SIMULTANEOUSLY, and nothing was solving my problem (as you can see here and here, if you want to). The first command is supposed to run Tshark for 5 seconds and capture network traffic (packets). The second command was supposed to generate some network packets and send them. The whole idea is that the network packets produced by the second command should be captured by Tshark, started by the first command.

In other words I needed to start Tshark in the background, and without waiting for it to finish, I needed to run the second command.

Finally I read somewhere if we end a terminal command with an &, the command is run in the BACKGROUND, and we can continue running other commands in the foreground. I thought this is the SOLUTION to my problem!

Then I wrote the following script.

PROBLEM:

When I execute this script in the browser, the web page keeps LOADING, and the loading never finishes. Also, apparently, tshark keeps running in the background capturing packets, instead of stopping after 5 seconds. I AM SAYING THIS BECAUSE THE PACKETS KEEP ADDING IN THE CAPTURE FILES (capture.pcap and capture.txt - the files where packets captured are stored, see the command in the script) UNLESS I MANUALLY END THE LOADING OF THE WEBPAGE IN THE BROWSER.

Also, when I manually stop the loading of the web page and open the capture.pcap file in wireshark, I see that the packets which were supposed to be sent ONCE by the second command have been sent HUNDREDS of times.

QUESTIONS:

  1. Does this mean that both the commands are being run again and again and again, like in an infinite loop?

  2. There are no loops in the script. Then why is this infinite-loop like behavior? How can I fix this?

SCRIPT:

shell_exec("tshark  -a duration:5  -w /var/www/html/Test/capture.pcap -V > capture.txt &");

shell_exec("./mtu  -d0  -a43020008  -g43010008  -i987654321  -s'Mary'  2>&1");

来源:https://stackoverflow.com/questions/43718834/exec-keeps-executing-the-command-again-and-again-like-an-infinite-loop-despit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!