Non syscall's wrappers but something like snprintf(), dprintf()
相关问题
- how to split a list into a given number of sub-lis
- Is shmid returned by shmget() unique across proces
- C#: How do i get 2 lists into one 2-tuple list in
- how to get running process information in java?
- F#: Storing and mapping a list of functions
If you're trying to capture a stack trace:
Typically
abort
would cause a core dump, which can be run through a debugger to produce the stack trace.Alternatively, a crude (but signal-safe) way of doing so would be to
fork
andexec
a separate utility (e.g. "pstack") to output a stack trace of your crashed task. Whenexec
-ing (afterfork
-ing, in the child), you'll need to pass your process ID usinggetppid
; and in the parent you'll need towait
for it to finish, before callingabort
.On the other hand, if you're trying to do a "clean" exit after SIGSEGV (e.g. ensuring C++ destructors get called, etc.) -- then you should be warned that POSIX says:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03_02:
and http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03_03:
This seems hard to determine, as you don't know what random unsafe function a library routine might decide to call. The list also might different between different versions of glibc, or if you take it to another Unix-like system. Seems like you'd have to analyze a lot of call stacks to find the answer, and even that may be a bit shaky from version to version, distro to distro.
Maybe you are not looking for alternative design approaches, but it seems like a better strategy would be: if your program has an event loop, make the signal handler very stupid and just setting some state that the event loop will pick up. That way you do the meaningful work outside of the signal handler.
Example: Let's say you've got a
poll()
loop somewhere. Maybe you could include a pipe that the signal handler can write to. Then thepoll()
loop does some non-trivial work based on being signaled by that.I am pretty sure you have to see the documentationEdit: How about this list then?
From
man signal
:Finally latest versions of
man 7 signal-safety
contain interested list: signal-safety.7.html