logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

pthread_sigmask.3p (6968B)


  1. '\" et
  2. .TH PTHREAD_SIGMASK "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. pthread_sigmask,
  12. sigprocmask
  13. \(em examine and change blocked signals
  14. .SH SYNOPSIS
  15. .LP
  16. .nf
  17. #include <signal.h>
  18. .P
  19. int pthread_sigmask(int \fIhow\fP, const sigset_t *restrict \fIset\fP,
  20. sigset_t *restrict \fIoset\fP);
  21. int sigprocmask(int \fIhow\fP, const sigset_t *restrict \fIset\fP,
  22. sigset_t *restrict \fIoset\fP);
  23. .fi
  24. .SH DESCRIPTION
  25. The
  26. \fIpthread_sigmask\fR()
  27. function shall examine or change (or both) the calling thread's
  28. signal mask, regardless of the number of threads in the process. The
  29. function shall be equivalent to
  30. \fIsigprocmask\fR(),
  31. without the restriction that the call be made in a single-threaded
  32. process.
  33. .P
  34. In a single-threaded process, the
  35. \fIsigprocmask\fR()
  36. function shall examine or change (or both) the signal mask of the
  37. calling thread.
  38. .P
  39. If the argument
  40. .IR set
  41. is not a null pointer, it points to a set of signals to be used to
  42. change the currently blocked set.
  43. .P
  44. The argument
  45. .IR how
  46. indicates the way in which the set is changed, and the application
  47. shall ensure it consists of one of the following values:
  48. .IP SIG_BLOCK 12
  49. The resulting set shall be the union of the current set and the signal
  50. set pointed to by
  51. .IR set .
  52. .IP SIG_SETMASK 12
  53. The resulting set shall be the signal set pointed to by
  54. .IR set .
  55. .IP SIG_UNBLOCK 12
  56. The resulting set shall be the intersection of the current set and the
  57. complement of the signal set pointed to by
  58. .IR set .
  59. .P
  60. If the argument
  61. .IR oset
  62. is not a null pointer, the previous mask shall be stored in the location
  63. pointed to by
  64. .IR oset .
  65. If
  66. .IR set
  67. is a null pointer, the value of the argument
  68. .IR how
  69. is not significant and the thread's signal mask shall be unchanged;
  70. thus the call can be used to enquire about currently blocked signals.
  71. .P
  72. If there are any pending unblocked signals after the call to
  73. \fIsigprocmask\fR(),
  74. at least one of those signals shall be delivered before the call to
  75. \fIsigprocmask\fR()
  76. returns.
  77. .P
  78. It is not possible to block those signals which cannot be ignored.
  79. This shall be enforced by the system without causing an error to be
  80. indicated.
  81. .P
  82. If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS
  83. signals are generated while they are blocked, the result is undefined,
  84. unless the signal was generated by the action of another process, or by
  85. one of the functions
  86. \fIkill\fR(),
  87. \fIpthread_kill\fR(),
  88. \fIraise\fR(),
  89. or
  90. \fIsigqueue\fR().
  91. .P
  92. If
  93. \fIsigprocmask\fR()
  94. fails, the thread's signal mask shall not be changed.
  95. .P
  96. The use of the
  97. \fIsigprocmask\fR()
  98. function is unspecified in a multi-threaded process.
  99. .SH "RETURN VALUE"
  100. Upon successful completion
  101. \fIpthread_sigmask\fR()
  102. shall return 0; otherwise, it shall return the corresponding error
  103. number.
  104. .P
  105. Upon successful completion,
  106. \fIsigprocmask\fR()
  107. shall return 0; otherwise, \-1 shall be returned,
  108. .IR errno
  109. shall be set to indicate the error, and the signal mask of the process
  110. shall be unchanged.
  111. .SH ERRORS
  112. The
  113. \fIpthread_sigmask\fR()
  114. and
  115. \fIsigprocmask\fR()
  116. functions shall fail if:
  117. .TP
  118. .BR EINVAL
  119. The value of the
  120. .IR how
  121. argument is not equal to one of the defined values.
  122. .P
  123. The
  124. \fIpthread_sigmask\fR()
  125. function shall not return an error code of
  126. .BR [EINTR] .
  127. .LP
  128. .IR "The following sections are informative."
  129. .SH EXAMPLES
  130. .SS "Signaling in a Multi-Threaded Process"
  131. .P
  132. This example shows the use of
  133. \fIpthread_sigmask\fR()
  134. in order to deal with signals in a multi-threaded process. It provides
  135. a fairly general framework that could be easily adapted/extended.
  136. .sp
  137. .RS 4
  138. .nf
  139. #include <stdio.h>
  140. #include <stdlib.h>
  141. #include <pthread.h>
  142. #include <signal.h>
  143. #include <string.h>
  144. #include <errno.h>
  145. \&...
  146. .P
  147. static sigset_t signal_mask; /* signals to block */
  148. .P
  149. int main (int argc, char *argv[])
  150. {
  151. pthread_t sig_thr_id; /* signal handler thread ID */
  152. int rc; /* return code */
  153. .P
  154. sigemptyset (&signal_mask);
  155. sigaddset (&signal_mask, SIGINT);
  156. sigaddset (&signal_mask, SIGTERM);
  157. rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
  158. if (rc != 0) {
  159. /* handle error */
  160. ...
  161. }
  162. /* any newly created threads inherit the signal mask */
  163. .P
  164. rc = pthread_create (&sig_thr_id, NULL, signal_thread, NULL);
  165. if (rc != 0) {
  166. /* handle error */
  167. ...
  168. }
  169. .P
  170. /* APPLICATION CODE */
  171. ...
  172. }
  173. .P
  174. void *signal_thread (void *arg)
  175. {
  176. int sig_caught; /* signal caught */
  177. int rc; /* returned code */
  178. .P
  179. rc = sigwait (&signal_mask, &sig_caught);
  180. if (rc != 0) {
  181. /* handle error */
  182. }
  183. switch (sig_caught)
  184. {
  185. case SIGINT: /* process SIGINT */
  186. ...
  187. break;
  188. case SIGTERM: /* process SIGTERM */
  189. ...
  190. break;
  191. default: /* should normally not happen */
  192. fprintf (stderr, "\enUnexpected signal %d\en", sig_caught);
  193. break;
  194. }
  195. }
  196. .fi
  197. .P
  198. .RE
  199. .SH "APPLICATION USAGE"
  200. None.
  201. .SH RATIONALE
  202. When a thread's signal mask is changed in a signal-catching function
  203. that is installed by
  204. \fIsigaction\fR(),
  205. the restoration of the signal mask on return from the signal-catching
  206. function overrides that change (see
  207. \fIsigaction\fR()).
  208. If the signal-catching function was installed with
  209. \fIsignal\fR(),
  210. it is unspecified whether this occurs.
  211. .P
  212. See
  213. \fIkill\fR()
  214. for a discussion of the requirement on delivery of signals.
  215. .SH "FUTURE DIRECTIONS"
  216. None.
  217. .SH "SEE ALSO"
  218. .IR "\fIexec\fR\^",
  219. .IR "\fIkill\fR\^(\|)",
  220. .IR "\fIsigaction\fR\^(\|)",
  221. .IR "\fIsigaddset\fR\^(\|)",
  222. .IR "\fIsigdelset\fR\^(\|)",
  223. .IR "\fIsigemptyset\fR\^(\|)",
  224. .IR "\fIsigfillset\fR\^(\|)",
  225. .IR "\fIsigismember\fR\^(\|)",
  226. .IR "\fIsigpending\fR\^(\|)",
  227. .IR "\fIsigqueue\fR\^(\|)",
  228. .IR "\fIsigsuspend\fR\^(\|)"
  229. .P
  230. The Base Definitions volume of POSIX.1\(hy2017,
  231. .IR "\fB<signal.h>\fP"
  232. .\"
  233. .SH COPYRIGHT
  234. Portions of this text are reprinted and reproduced in electronic form
  235. from IEEE Std 1003.1-2017, Standard for Information Technology
  236. -- Portable Operating System Interface (POSIX), The Open Group Base
  237. Specifications Issue 7, 2018 Edition,
  238. Copyright (C) 2018 by the Institute of
  239. Electrical and Electronics Engineers, Inc and The Open Group.
  240. In the event of any discrepancy between this version and the original IEEE and
  241. The Open Group Standard, the original IEEE and The Open Group Standard
  242. is the referee document. The original Standard can be obtained online at
  243. http://www.opengroup.org/unix/online.html .
  244. .PP
  245. Any typographical or formatting errors that appear
  246. in this page are most likely
  247. to have been introduced during the conversion of the source files to
  248. man page format. To report such errors, see
  249. https://www.kernel.org/doc/man-pages/reporting_bugs.html .