开发者

Fork shell script (not &)

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 w开发者_运维技巧ay to fork an independent, non-child process for the shell script, so I can restart Apache?

Thx, Mr B


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 &
disown

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


Take a look at nohup, may fit you needs.

let's say you have a script called test.sh

for i in $(seq 100); do
  echo $i >> test.temp
  sleep 1;
done

if you run nohup ./test.sh & you can kill the shell and the process stay alive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜