启动子进程的最佳方法是什么,当父进程终止时,子进程也将被终止。
我可以看到我的过程是一棵树:
1 26152 26150 26150 ? -1 Sl 1000 0:00 /usr/bin/perl /usr/local/bin/disp
26152 26171 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_500
26171 26172 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_500 600
26152 26174 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_1000
26174 26175 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_1000 600
26152 26177 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_2000
26177 26178 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_2000 600
26152 26181 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_5000
26181 26186 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_5000 600
26152 26189 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_15000
26189 26190 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_15000 600
26152 26195 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_30000
26195 26197 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_30000 600
26152 26198 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_60000
26198 26201 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_60000 28800
26152 26213 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_900000
26213 26217 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_900000 86400
26152 26219 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_3600000
26219 26225 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_3600000 86400
26152 26233 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_86400000
26233 26235 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_86400000 86400
但是当我杀死父进程(kill -9 26152
)时,它不会删除子进程。相反,子进程父进程父进程正在成为父进程
1 26171 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_500
26171 26172 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_500 600
1 26174 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_1000
26174 26175 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_1000 600
1 26177 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_2000
26177 26178 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_2000 600
1 26181 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_5000
26181 26186 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_5000 600
1 26189 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_15000
26189 26190 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_15000 600
1 26195 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_30000
26195 26197 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_30000 600
1 26198 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_60000
26198 26201 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_60000 28800
1 26213 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_900000
26213 26217 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_900000 86400
1 26219 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_3600000
26219 26225 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_3600000 86400
1 26233 26150 26150 ? -1 S 1000 0:00 /bin/bash /var/tmp/job_86400000
26233 26235 26150 26150 ? -1 S 1000 0:00 \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_86400000 86400
请帮助我。我做错了什么,或者我是否需要在开始这个过程时做一些改变?
答案 0 :(得分:3)
您可以告诉父母将HUP
信号发送给流程组,
use sigtrap qw(die normal-signals);
END {
kill('HUP', -$$);
}
PROCESS号为零或负数时的kill行为取决于操作系统。例如,在符合POSIX的系统上,零将发出当前进程组的信号,-1将发出所有进程的信号,任何其他负的进程号将作为负信号编号并终止指定的整个进程组。