Sample Header Ad - 728x90

Why does the linux manual say nothing about generating a SIGCHLD signal when the child resumes execution?

3 votes
2 answers
136 views
I am using linux (ubuntu). When I type man 7 signal (manual 2020-12-21) in my terminal, I find the following for the SIGCHLD: SIGCHLD P1990 Ign Child stopped or terminated So, it states that the SIGCHLD signal is only generated in this two cases. It says nothing about when the child process continues. However, in POSIX, it states the following: SIGCHLD Child process terminated, stopped, [XSI] or continued. Thus, when OS supports XSI, this signal is also generated when the child continues. I also write some simple child/parent programs and can confirm it. **Since linux supports XSI, why does the manual not include "continue" scenario for the SIGCHLD as well? What is the purpose of manual when it's incomplete (or I am missing its purpose?)** Also I found [the following answers](https://unix.stackexchange.com/questions/6332/what-causes-various-signals-to-be-sent) for SIGCHLD then incomplete. --- Below is the code. It is a simple golang code. The parent starts the child via the classic fork/exec. It then registers a handler for the SIGCHLD signal and that's it. Both parent and child print a message every 10 seconds. After building both programs, I run them via ./parent command. I control the behavior (T R/S state) of the child process via kill -SISTOP child_process_id and kill -SIGCONT child_process_id. Parent:
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)
	}
}
Child:
package main

import (
	"fmt"
	"time"
)

func main() {
	for {
		fmt.Println("hi from child")
		time.Sleep(time.Second * 10)
	}
}
Asked by Yakog (517 rep)
Jan 25, 2025, 02:39 PM
Last activity: Feb 2, 2025, 01:30 PM