Created
December 9, 2023 23:09
-
-
Save psnszsn/229f8da376c46cb72adab2210d75c9fd to your computer and use it in GitHub Desktop.
zig signalfd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn signals(io: *IO) !void { | |
const os = std.os; | |
var mask = os.linux.empty_sigset; | |
os.linux.sigaddset(&mask, os.SIG.INT); | |
os.linux.sigaddset(&mask, os.SIG.TSTP); | |
const r = os.linux.sigprocmask(os.SIG.BLOCK, &mask, null); | |
const sigfd = try os.signalfd(-1, &mask, 0); | |
std.debug.print("R{}\n", .{r}); | |
while (true) { | |
const events = try io.poll_add(sigfd, os.POLL.IN); | |
std.debug.assert(events == 1); | |
var si: os.linux.signalfd_siginfo = undefined; | |
const bytes_read = try io.read(sigfd, std.mem.asBytes(&si), 0); | |
std.debug.assert(bytes_read == @sizeOf(@TypeOf(si))); | |
std.debug.print("si: {}\n", .{si}); | |
std.debug.print("PID: {}\n", .{os.linux.getpid()}); | |
os.exit(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment