1.\" Copyright (c) 1996 The NetBSD Foundation, Inc. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to The NetBSD Foundation 5.\" by Paul Kranenburg. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 20.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26.\" POSSIBILITY OF SUCH DAMAGE. 27.\" 28.\" $NetBSD: psignal.9,v 1.1 1996/06/22 22:57:35 pk Exp $ 29.\" $FreeBSD$ 30.\" 31.Dd July 14, 2023 32.Dt PSIGNAL 9 33.Os 34.Sh NAME 35.Nm psignal , 36.Nm kern_psignal , 37.Nm pgsignal , 38.Nm tdsignal 39.Nd post signal to a thread, process, or process group 40.Sh SYNOPSIS 41.In sys/types.h 42.In sys/signalvar.h 43.Ft void 44.Fn kern_psignal "struct proc *p" "int signum" 45.Ft void 46.Fn pgsignal "struct pgrp *pgrp" "int signum" "int checkctty" 47.Ft void 48.Fn tdsignal "struct thread *td" "int signum" 49.Sh DESCRIPTION 50These functions post a signal to a thread or one or more processes. 51The argument 52.Fa signum 53common to all three functions should be in the range 54.Bq 1- Ns Dv NSIG . 55.Pp 56The 57.Fn kern_psignal 58function posts signal number 59.Fa signum 60to the process represented by the process structure 61.Fa p . 62The 63.Fn kern_psignal 64function used to be called 65.Fn psignal 66but was renamed in order to eliminate a name collision with the libc 67function of that name and facilitate code reuse. 68With a few exceptions noted below, the target process signal disposition is 69updated and is marked as runnable, so further handling of the signal is done 70in the context of the target process after a context switch. 71Note that 72.Fn kern_psignal 73does not by itself cause a context switch to happen. 74.Pp 75The target process is not marked as runnable in the following cases: 76.Bl -bullet -offset indent 77.It 78The target process is sleeping uninterruptibly. 79The signal will be 80noticed when the process returns from the system call or trap. 81.It 82The target process is currently ignoring the signal. 83.It 84If a stop signal is sent to a sleeping process that takes the 85default action 86(see 87.Xr sigaction 2 ) , 88the process is stopped without awakening it. 89.It 90.Dv SIGCONT 91restarts a stopped process 92(or puts them back to sleep) 93regardless of the signal action 94(e.g., blocked or ignored). 95.El 96.Pp 97If the target process is being traced 98.Fn kern_psignal 99behaves as if the target process were taking the default action for 100.Fa signum . 101This allows the tracing process to be notified of the signal. 102.Pp 103The 104.Fn pgsignal 105function posts signal number 106.Fa signum 107to each member of the process group described by 108.Fa pgrp . 109If 110.Fa checkctty 111is non-zero, the signal will be posted only to processes that have 112a controlling terminal. 113.Fn pgsignal 114is implemented by walking along the process list headed by the field 115.Li pg_members 116of the process group structure 117pointed at by 118.Fa pgrp 119and calling 120.Fn kern_psignal 121as appropriate. 122If 123.Fa pgrp 124is 125.Dv NULL 126no action is taken. 127.Pp 128The 129.Fn tdsignal 130function posts signal number 131.Fa signum 132to the thread represented by the thread structure 133.Fa td . 134.Sh SEE ALSO 135.Xr sigaction 2 , 136.Xr signal 9 , 137.Xr tsleep 9 138.Sh HISTORY 139The 140.Fn psignal 141function was renamed to 142.Fn kern_psignal 143in 144.Fx 9.0 . 145