tsigexitcode.nim 639 B

123456789101112131415161718192021222324
  1. discard """
  2. joinable: false
  3. disabled: windows
  4. """
  5. import os, osproc, posix, strutils
  6. proc main() =
  7. if paramCount() > 0:
  8. let signal = cint parseInt paramStr(1)
  9. discard posix.raise(signal)
  10. else:
  11. # synchronize this list with lib/system/except.nim:registerSignalHandler()
  12. let sigs = [SIGINT, SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, SIGPIPE]
  13. for s in sigs:
  14. let (_, exitCode) = execCmdEx(quoteShellCommand [getAppFilename(), $s])
  15. if s == SIGPIPE:
  16. # SIGPIPE should be ignored
  17. doAssert exitCode == 0, $(exitCode, s)
  18. else:
  19. doAssert exitCode == 128+s, $(exitCode, s)
  20. main()