I'm accessing a webserver via PHP. I want to update some info in the Apache configs, so I start a shell script that makes the changes. Then I want to stop and restart Apache.

Problem: as soon as I stop Apache, my process stops and my shell script, being a child process, is killed. Apache never restarts. This also happens with Apache restart.

Is there a way to fork an independent, non-child process for the shell script, so I can restart Apache?

Thx, Mr B


What's the command? /etc/init.d/apache2 stop ? Maybe you can use /etc/init.d/apache2 restart ? PS. to whomever suggested the same with apachectl, no need to delete a comment because it is similar to another one.

Written by Benoit

Maybe also apachectl graceful may be a better option...

Written by Enrico Carlesso

Accepted Answer

You can use disown:

disown [-ar] [-h] [jobspec ...]

Without options, each jobspec is removed from the table of active jobs. If the `-h' option is given, the job is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If jobspec is not present, and neither the `-a' nor `-r' option is supplied, the current job is used. If no jobspec is supplied, the `-a' option means to remove or mark all jobs; the `-r' option without a jobspec argument restricts operation to running jobs.

./myscript.sh &

./myscript.sh will continue running even if the script that started it dies.

Written by sfussenegger
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki