Skip to content

Instantly share code, notes, and snippets.

View SarKerson's full-sized avatar

Eric Yao SarKerson

View GitHub Profile
@SarKerson
SarKerson / my_questions.md
Created December 19, 2018 14:38
I implement a sigprocmask program that described in CSAPP, but the parent-process only received SIGCHLD from its children once or twice, no mater how many times it fork()

the expected result would be:(the number of add is the same as del)

add job 12987
add job 12988
Wed Dec 19 22:20:59 CST 2018
del from 12987
Wed Dec 19 22:21:00 CST 2018
del from 12988
add job 12989
add job 12990

version3_利用sigprocmask同步父子进程

期望输出: done fork先于got signal,某一刻出现的done fork数量大于等于got signal

code:

#include <sys/wait.h>
#include <sys/signal.h>
#include <errno.h>
#include "apue.h"
@SarKerson
SarKerson / version4_process_in_main.md
Created December 21, 2018 06:32
version4_process_in_main.md

显式等待信号

该程序在主函数中等待SIGCHLD,直到信号处理函数对某个全局变量进行修改后,主函数捕捉该变化,再继续运行。

sigsuspend(mask)

该函数使用mask代替当前的信号屏蔽字,将程序挂起,直到捕获到信号,其行为要么运行一个handler,要么终止程序。

result(先运行handler再运行主函数后边的处理)

Hello from child
# Got signal from child!