How to stop background process from running shell script
P粉722409996
P粉722409996 2023-09-03 18:16:08
0
1
697
<p>I'm trying to run mysqld in the background to execute some commands using the mysql client, but when I switch the process to the foreground, my script stops running. This is the script I use: </p> <pre class="brush:sh;toolbar:false;">set -m daemon="/usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0 $@" $daemon & exec echo "Test" exec fg %1 </pre> <p>I am not a shell script programming expert, I looked on some websites and found this method of executing commands. </p>
P粉722409996
P粉722409996

reply all(1)
P粉521748211

No. The script stops after exec echo "Test". exec Replace the current process (i.e. shell script) with the following command. You can verify by:

daemon="/usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0 $@"
$daemon &
exec echo "Test"
echo "Second Test"
exec fg %1

The solution is simple: don't use exec.

BTW: It's not clear why you want to use fg in a shell script. In an interactive shell, fg has no function only within scripts.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template