Query all Linux Traps that are set

I want to query Linux for all Traps that are defined, much like the "trap" command. Anyone know of a library for this? Would rather avoid using the "trap" command itself if possible.


the nix crate, specifically nix::sys::signal::Signal::iterator() might offer the functionality you want

(though, thinking of it, trap is a shell built-in not a separate binary, your program cannot learn the trap settings of the parent shell)

If you mean signals, then:

  • To use and set them, you can use the signal-hook crate.
  • To list what's available, you can look it once in docs or with kill -l. These don't change that often if at all, they don't differ one linux to another.
  • If you really wanted to check if specific signal number is available, calling signal with that specific number will return an error if it isn't available.

But maybe explain better what exactly you want to do, because the question is not very clear.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.