Deutsch English Français Italiano |
<slrnv3fm5e.jrj.naddy@lorvorc.mips.inka.de> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail From: Christian Weisgerber <naddy@mips.inka.de> Newsgroups: comp.unix.shell Subject: Cleaning up background processes Date: Sun, 5 May 2024 19:06:22 -0000 (UTC) Message-ID: <slrnv3fm5e.jrj.naddy@lorvorc.mips.inka.de> Injection-Date: Sun, 5 May 2024 19:06:22 -0000 (UTC) Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1"; logging-data="20340"; mail-complaints-to="usenet@mips.inka.de" User-Agent: slrn/1.0.3 (FreeBSD) Bytes: 1698 Lines: 24 Is there a standard POSIX shell idiom to clean up background processes? You have a shell script that starts some background process with &. Now you want to make sure that the background process terminates when the shell script terminates. In particular, when it terminates due to special circumstances. A noninteractive shell doesn't use job control, so the background process shares the same process group. That's great! When somebody hits ^C, SIGINT is sent to the whole process group. The same for ^\ and SIGQUIT, and for SIGHUP when the modem hangs up^W^W^Wxterm is closed. So the background process will be terminated by default. Except... bash seems to block SIGINT for background processes. As does FreeBSD's sh with both SIGINT and SIGQUIT. What now? Also, the shell script is typically invoked from some implementation of make(1), which seems to add more complications. This seems like a sufficiently common problem that there must be a standard solution. -- Christian "naddy" Weisgerber naddy@mips.inka.de