troubleshooting Question

stop bash if php script halted

Avatar of style-sheets
style-sheets asked on
LinuxPHPSSH / Telnet Software
9 Comments1 Solution725 ViewsLast Modified:
Hi,

I have a php script that calls a bash script via shell_exec() function:

<?php
	set_time_limit(0);

	$file_name = "/home/full/path/file.txt";
	shell_exec('bash bash_script.sh "' . $file_name . '"');
?>

The bash script called looks like this:

# ======================================================= #
i=0
while read LINE
do
	bash child_script.sh "${i}" "${file_size}" < /dev/null &
	i=$(($i+1))
done < "${file_name}.txt"
# ======================================================= #

# Wait until all jobs are done
for job in `jobs -p`
do
    # echo $job
    wait $job || let "FAIL+=1"
done

As you can see, this bash script calls another "child" bash script. I'm basically simulating multi-threading by using &

It works super well (execution speed is insanely fast), except that if user hits the ESCAPE key or stops the php script, these child bash script aren't killed & becomes zombie processes.

This is badly affecting my (dedicated) server. Is there a way to prevent this?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros