在使用时避免僵尸进程

我正在使用在基于Centos的Docker容器中安排脚本。

例如echo "bash /path/to/script.sh" | at now + 1 minute echo "bash /path/to/script.sh" | at now + 1 minute

它大部分能按预期工作,除了每分钟都会导致一个僵尸进程。 我猜这个行为与文档中的这一行有关:

  1. 除了环境variables,当前工作目录,文件创build掩码(请参阅umask(1))和系统资源限制外,在单独的shell调用中执行at-job,运行在不带控制terminal的单独进程组。

我已经看到,并尝试从stream程表中删除僵尸进程的build议无济于事。

我可以让僵尸PS离开吗?还是有另一种方法来做到这一点,不会以同样的僵尸PS结束?

编辑:其中一个脚本的内容:

 #!/bin/bash exec 1> >(logger -s -t $(basename $0)) 2>&1 #probe the seed node if this isn't the seed node # set -ex [[ `hostname` =~ -([0-9]+)$ ]] || exit 1 ordinal=${BASH_REMATCH[1]} #if this is the first node then attempt to probe second until successful if [[ $ordinal -eq 0 ]]; then while ! gluster peer probe {{gluster.service_name}}-1.{{gluster.service_name}}.default.svc.cluster.local; do sleep 2; done fi #if this is the second node then probe the first to create the trusted pool if [[ $ordinal -eq 1 ]]; then while ! gluster peer probe {{gluster.service_name}}-0.{{gluster.service_name}}.default.svc.cluster.local; do sleep 2; done fi 

我忘了回复,我只是使用cron来解决这个问题。

 (crontab -l 2>/dev/null; echo "*/1 * * * * /path/to/job -with args") | crontab - 

请参阅https://stackoverflow.com/a/9625233/400048

请注意,如果在Docker中运行,则需要启动crond。