signal.texi 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. @node POSIX signals
  2. @section Signals
  3. @stindex posix-signals
  4. There are two varieties of signals available, named & anonymous. A
  5. @dfn{named} signal is one for which there is provided a symbolic name,
  6. such as @code{kill} or @code{pipe}. Anonymous signals are those that
  7. the operating system provided but for which POSIX does not define a
  8. symbolic name, only a number, and which may not have meaning on other
  9. operating systems. Named signals preserve their meaning through heap
  10. image dumps; anonymous signals may not be dumped in heap images. (If
  11. they are, a warning is signalled, and they are replaced with a special
  12. token that denotes a non-portable signal.) Not all named signals are
  13. available from all operating systems, and there may be multiple names
  14. for a single operating system signal number.
  15. @deffn syntax signal name @returns{} signal
  16. @deffnx procedure name->signal symbol @returns{} signal or @code{#f}
  17. @deffnx procedure integer->signal integer @returns{} signal
  18. @deffnx procedure signal? object @returns{} boolean
  19. @deffnx procedure signal-name signal @returns{} symbol or @code{#f}
  20. @deffnx procedure signal-os-number signal @returns{} integer
  21. @deffnx procedure signal=? signal@suba{a} signal@suba{b} @returns{} boolean
  22. @code{Signal} evaluates to the signal object with the known symbolic
  23. name @var{name}. It is an error if @var{name} is not recognized as any
  24. signal's name. @code{Name->signal} returns the signal corresponding
  25. with the given @var{name} or @code{#f} if no such signal is known.
  26. @code{Integer->signal} returns a signal, named or anonymous, with the
  27. given OS number. @code{Signal?} is the disjoint type predicate for
  28. signal objects. @code{Signal-name} returns the symbolic name of
  29. @var{signal} if it is a named signal or @code{#f} if it is an anonymous
  30. signal. @code{Signal-OS-number} returns the operating system's integer
  31. value of @var{signal}. @code{Signal=?} tests whether two signals are
  32. the same, @ie{} whether their OS numbers are equal equal.
  33. These are all of the symbols that POSIX defines.
  34. @table @code
  35. @item abrt
  36. abnormal termination (as by @code{abort(3)})
  37. @item alrm
  38. timeout signal (as by @code{alarm(2)})
  39. @item fpe
  40. floating point exception
  41. @item hup
  42. hangup on controlling terminal or death of controlling process
  43. @item ill
  44. illegal instruction
  45. @item int
  46. interrupt --- interaction attention
  47. @item kill
  48. termination signal, cannot be caught or ignored
  49. @item pipe
  50. write was attempted on a pipe with no readers
  51. @item quit
  52. interaction termination
  53. @item segv
  54. segmentation violation --- invalid memory reference
  55. @item term
  56. termination signal
  57. @item usr1
  58. @itemx usr2
  59. for use by applications
  60. @item chld
  61. child process stopped or terminated
  62. @item cont
  63. continue if stopped
  64. @item stop
  65. stop immediately, cannot be caught or ignored
  66. @item tstp
  67. interactive stop
  68. @item ttin
  69. read from control terminal attempted by a background process
  70. @item ttou
  71. write to control terminal attempted by a background process
  72. @item bus
  73. bus error --- access to undefined portion of memory
  74. @end table
  75. There are also several other signals whose names are allowed to be
  76. passed to @code{signal} that are not defined by POSIX, but that are
  77. recognized by many operating systems.
  78. @table @code
  79. @item trap
  80. trace or breakpoint trap
  81. @item iot
  82. synonym for @code{abrt}
  83. @item emt
  84. @item sys
  85. bad argument to routine (SVID)
  86. @item stkflt
  87. stack fault on coprocessor
  88. @item urg
  89. urgent condition on socket (4.2 BSD)
  90. @item io
  91. I/O now possible (4.2 BSD)
  92. @item poll
  93. synonym for @code{io} (System V)
  94. @item cld
  95. synonym for @code{chld}
  96. @item xcpu
  97. CPU time limit exceeded (4.2 BSD)
  98. @item xfsz
  99. file size limit exceeded (4.2 BSD)
  100. @item vtalrm
  101. virtual alarm clock (4.2 BSD)
  102. @item prof
  103. profile alarm clock
  104. @item pwr
  105. power failure (System V)
  106. @item info
  107. synonym for @code{pwr}
  108. @item lock
  109. file lock lost
  110. @item winch
  111. Window resize signal (4.3 BSD, Sun)
  112. @item unused
  113. @end table
  114. @end deffn
  115. @subsection Sending & receiving signals
  116. @deffn procedure signal-process pid signal @returns{} unspecified
  117. Sends a signal represented by @var{signal} to the process identified by
  118. @var{pid}.
  119. @end deffn
  120. @cindex signal queues
  121. Signals received by the Scheme process can be obtained via one or more
  122. @dfn{signal queues}. Each signal queue has a list of monitored signals
  123. and a queue of received signals that have yet to be consumed from the
  124. queue. When the Scheme process receives a signal, that signal is added
  125. to the signal queues that are currently monitoring the signal received.
  126. @deffn procedure make-signal-queue signal-list @returns{} signal-queue
  127. @deffnx procedure signal-queue? object @returns{} boolean
  128. @deffnx procedure signal-queue-monitored-signals signal-queue @returns{} signal-list
  129. @deffnx procedure dequeue-signal! signal-queue @returns{} signal (may block)
  130. @deffnx procedure maybe-dequeue-signal! signal-queue @returns{} signal or @code{#f}
  131. @code{Make-signal-queue} returns a new signal queue that will monitor
  132. all of the signals in the given list. @code{Signal-queue?} is the
  133. disjoint type predicate for signal queues.
  134. @code{Signal-queue-monitored-signals} returns a freshly-allocated list
  135. of the signals currently monitored by @var{signal-queue}.
  136. @code{Dequeue-signal!} & @code{maybe-dequeue-signal!} both access the
  137. next signal ready to be read from @var{signal-queue}. If the signal
  138. queue is empty, @code{dequeue-signal!} will block until a signal is
  139. received, while @code{maybe-dequeue-signal!} will immediately return
  140. @code{#f}.
  141. @end deffn
  142. @strong{Note:} There is a bug in the current system that causes an
  143. erroneous deadlock to occur if threads are blocked waiting for signals
  144. and no other threads are available to run. A workaround is to create a
  145. thread that sleeps for a long time, which prevents any deadlock errors
  146. (including real ones):
  147. @lisp
  148. > ,open threads
  149. > (spawn (lambda ()
  150. ;; Sleep for a year.
  151. (sleep (* 1000 60 60 24 365))))@end lisp
  152. @deffn procedure add-signal-queue-signal! signal-queue signal @returns{} unspecified
  153. @deffnx procedure remove-signal-queue-signal! signal-queue signal @returns{} unspecified
  154. These add & remove signals from signal queues' list of signals to
  155. monitor. Note that @code{remove-signal-queue-signal!} also removes any
  156. pending signals from the queue, so @code{dequeue-signal!} &
  157. @code{maybe-dequeue-signal!} will only ever return signals that are
  158. on the queue's list of monitored signals when they are called.
  159. @end deffn