AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 790116
Accepted
Yakog
Yakog
Asked: 2025-01-25 22:39:33 +0800 CST2025-01-25 22:39:33 +0800 CST 2025-01-25 22:39:33 +0800 CST

为什么 Linux 手册没有提到子进程恢复执行时生成 SIGCHLD 信号?

  • 772

我正在使用 Linux(ubuntu)。

当我man 7 signal在终端中输入 (manual 2020-12-21) 时,我发现 SIGCHLD 出现以下情况:

SIGCHLD      P1990      Ign     Child stopped or terminated

因此,它表明SIGCHLD仅在这两种情况下才会生成信号。它并未说明子进程何时继续运行。

然而,在 POSIX 中,它规定如下:

SIGCHLD Child process terminated, stopped,

[XSI] or continued.

因此,当 OS 支持 XSI 时,子进程继续时也会生成此信号。我还编写了一些简单的子进程/父进程程序,可以确认这一点。既然 Linux 支持 XSI,为什么手册中不包括 SIGCHLD 的“继续”场景?如果手册不完整(或者我不明白它的用途),那么手册的目的是什么?

此外,我发现以下有关SIGCHLD 的答案不完整。


下面是代码。这是一段简单的 golang 代码。父进程通过经典的 fork/exec 启动子进程。然后它为 SIGCHLD 信号注册一个处理程序,就这样。父进程和子进程每 10 秒打印一条消息。构建两个程序后,我通过命令运行它们。我通过和控制子进程的./parent行为(T<->状态) 。R/Skill -SISTOP child_process_idkill -SIGCONT child_process_id

家长:

package main

import (
    "fmt"
    "os"
    "os/signal"
    "syscall"
    "time"
)

func main() {
    attr := &syscall.ProcAttr{
        Files: []uintptr{0, 1, 2},
    }

    _, err := syscall.ForkExec("./child/child", []string{"child"}, attr)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }

    ch := make(chan os.Signal, 1)
    signal.Notify(ch, syscall.SIGCHLD)

    go func() {
        for {
            select {
            case <-ch:
                fmt.Println("SIGNAL")
            }
        }
    }()

    for {
        fmt.Println("Parent is live")
        time.Sleep(10 * time.Second)
    }
}

孩子:

package main

import (
    "fmt"
    "time"
)

func main() {
    for {
        fmt.Println("hi from child")
        time.Sleep(time.Second * 10)
    }
}
signals
  • 2 2 个回答
  • 85 Views

2 个回答

  • Voted
  1. Best Answer
    Arkadiusz Drabczyk
    2025-02-02T21:30:01+08:002025-02-02T21:30:01+08:00

    该措辞已在上游 linux-man 存储库中得到修复:

    commit ac93c406a779bd0def5817d78c30f8a25bb318b9 (origin/contrib)
    Author: Arkadiusz Drabczyk <[email protected]>
    Date:   Sun Feb 2 14:03:31 2025 +0100
    
        man/man7/signal.7: Update definition of SIGCHLD for POSIX.1-2001
    
        This is an XSI extension supported by Linux.
    
        Link: <https://unix.stackexchange.com/q/790116/72304>
        Link: <https://lore.kernel.org/linux-man/Z5U0Wh_KF3Ki62Pk@comp../>
        Signed-off-by: Arkadiusz Drabczyk <[email protected]>
        Message-ID: <[email protected]>
        Signed-off-by: Alejandro Colomar <[email protected]>
    
    diff --git a/man/man7/signal.7 b/man/man7/signal.7
    index dd04c6d1a..83251e071 100644
    --- a/man/man7/signal.7
    +++ b/man/man7/signal.7
    @@ -360,7 +360,8 @@ Linux supports the standard signals listed below.
     The second column of the table indicates which standard (if any)
     specified the signal: "P1990" indicates that the signal is described
     in the original POSIX.1-1990 standard;
    -"P2001" indicates that the signal was added in SUSv2 and POSIX.1-2001.
    +"P2001" indicates that the signal was added or its definition changed
    +in SUSv2 and POSIX.1-2001.
     .TS
     l c c l
     ____
    @@ -369,7 +370,7 @@ Signal      Standard        Action  Comment
     SIGABRT        P1990   Core    Abort signal from \fBabort\fP(3)
     SIGALRM        P1990   Term    Timer signal from \fBalarm\fP(2)
     SIGBUS P2001   Core    Bus error (bad memory access)
    -SIGCHLD        P1990   Ign     Child stopped or terminated
    +SIGCHLD        P2001   Ign     Child stopped, terminated, or continued
     SIGCLD \-      Ign     A synonym for \fBSIGCHLD\fP
     SIGCONT        P1990   Cont    Continue if stopped
     SIGEMT \-      Term    Emulator trap
    

    在您的系统上升级 man-pages 包可能需要一些时间,因此您可以克隆开发存储库并在您的系统上获得最新版本的手册页:

    $ git -c http.sslVerify=false clone https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git
    Cloning into 'man-pages'...
    Fetching objects: 166851, done.
    Checking connectivity: 166851, done.
    $ cd man-pages
    $ git checkout ac93c406a779bd0def5817d78c30f8a25bb318b9
    Note: switching to 'ac93c406a779bd0def5817d78c30f8a25bb318b9'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by switching back to a branch.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -c with the switch command. Example:
    
      git switch -c <new-branch-name>
    
    Or undo this operation with:
    
      git switch -
    
    Turn off this advice by setting config variable advice.detachedHead to false
    
    HEAD is now at ac93c406a man/man7/signal.7: Update definition of SIGCHLD for POSIX.1-2001
    $ man ./man/man7/signal.7 | less '+/SIGCHLD'
    
    • 1
  2. Sotto Voce
    2025-01-26T03:13:04+08:002025-01-26T03:13:04+08:00

    要回答问题标题中的“为什么不”,我想说signal(7)手册页并不是查找内核使用特定信号的所有方式的综合目录的地方。手册页仅提供每个信号含义的简要描述。这与其他复杂、详细的主题(如gdb(1)和awk)一致,它们的手册页仅以基本的一般术语解释命令和命令行选项。全面深入的介绍留给书籍和大型网站。

    手册页在信息量和复杂程度方面是有限的。对于简单的命令,手册页就足够了。与计算机中的其他一切一样,手册页也有优点和缺点。它们适合记录某些内容,但不适合记录其他内容。对于信号等操作系统内部信息,它们不够用,而期望手册页能够完整解释所有内容只会让您失望。

    • 0

相关问题

  • 如何将中断信号限制在子进程中?

  • 陷阱处理程序不起作用?

  • 以两种不同的方式处理 SIGALRM

  • 为什么已经存在 SIGSTOP 时存在 SIGTSTP?

  • 调试的信号编号是 1 到 64 中的哪个数字?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve