父鱼壳进程终止后立即终止子进程? [英] Terminate child process as soon as the parent fish shell process terminates?

查看:72
本文介绍了父鱼壳进程终止后立即终止子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一个 fish shell 作为后台作业,并从中生成 inotifywait(一个监视指定文件并仅在返回后返回的进程)已更改).

I'm spawning a fish shell as a background job and from it I'm spawning inotifywait (a process that watches a specified file and returns only once it has been changed).

然而,后来在一个未指定的时间点(此时不能保证 inotifywait 已经返回),我正在杀死产生的 fish shellinotifywait.

Later on, however, at an unspecified point in time (at which point it's not guaranteed that inotifywait had returned), I'm killing the fish shell that spawned inotifywait.

我的目标是让 inotifywait 在产生它的 PPID 终止时自动终止.有没有办法做到这一点?

My goal is for inotifywait to terminate automatically as soon as the PPID that spawned it terminates. Is there any way to do this?

fish -c "inotifywait -qq $somefile && ..." &
# time passes, inotifywait hasn't returned
kill -15 (jobs -lp)
# the fish process is now terminated, but inoyifywait remains

我现在使用的临时 hack 是简单地更新正在观看的文件的访问时间(使用诸如 touch 之类的实用程序),以便 inotifywait终于回来了.

The temporary hack I'm using right now is to simply update the access time of the file being watched (with a utility such as touch) so that inotifywait would finally return.

我在 linux 4.20.11 上使用 fish 3.0.1.

I'm using fish 3.0.1 on linux 4.20.11.

推荐答案

不要在任何需要正常作业控制语义的情况下使用fish.Fish 是我用过的最好的交互式 shell.多年来,它一直是我的主要登录 shell.但是它的工作控制一直被打破到第一个版本.为了好玩,这样做:

Don't use fish for any situation where normal job control semantics are expected. Fish is the best interactive shell I've ever used. It's been my primary login shell for several years. But it's job control has been broken all the way back to the first version. For fun do this:

fish -c 'trap "echo WTF; exit 3" TERM; sleep 666' &
kill (jobs -lp)

您不会看到WTF"消息,背景的鱼壳也不会终止.现在 ps waux |grep sleep 并终止睡眠进程.您应该会在终端上看到WTF"消息,并且您的交互式 shell 将报告后台鱼已终止.

You won't see the "WTF" message and the backgrounded fish shell won't terminate. Now ps waux | grep sleep and kill the sleep process. You should see the "WTF" message on your terminal and your interactive shell will report the background fish has terminated.

对于这种情况,最简单的解决方案是将 bash/ksh/sh 用于后台脚本.

For this type of situation the simplest solution is to just use bash/ksh/sh for the backgrounded script.

这篇关于父鱼壳进程终止后立即终止子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆