rustix/process/
kill.rs

1use crate::process::Pid;
2use crate::{backend, io};
3
4pub use crate::signal::Signal;
5
6/// `kill(pid, sig)`—Sends a signal to a process.
7///
8/// # References
9///  - [POSIX]
10///  - [Linux]
11///
12/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html
13/// [Linux]: https://man7.org/linux/man-pages/man2/kill.2.html
14#[inline]
15#[doc(alias = "kill")]
16pub fn kill_process(pid: Pid, sig: Signal) -> io::Result<()> {
17    backend::process::syscalls::kill_process(pid, sig)
18}
19
20/// `kill(-pid, sig)`—Sends a signal to all processes in a process group.
21///
22/// If `pid` is [`Pid::INIT`], this sends a signal to all processes the current
23/// process has permission to send signals to, except process `Pid::INIT`,
24/// possibly other system-specific processes, and on some systems, the current
25/// process.
26///
27/// # References
28///  - [POSIX]
29///  - [Linux]
30///
31/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html
32/// [Linux]: https://man7.org/linux/man-pages/man2/kill.2.html
33#[inline]
34#[doc(alias = "kill")]
35pub fn kill_process_group(pid: Pid, sig: Signal) -> io::Result<()> {
36    backend::process::syscalls::kill_process_group(pid, sig)
37}
38
39/// `kill(0, sig)`—Sends a signal to all processes in the current process
40/// group.
41///
42/// # References
43///  - [POSIX]
44///  - [Linux]
45///
46/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html
47/// [Linux]: https://man7.org/linux/man-pages/man2/kill.2.html
48#[inline]
49#[doc(alias = "kill")]
50pub fn kill_current_process_group(sig: Signal) -> io::Result<()> {
51    backend::process::syscalls::kill_current_process_group(sig)
52}
53
54/// `kill(pid, 0)`—Check validity of pid and permissions to send signals to
55/// the process, without actually sending any signals.
56///
57/// # References
58///  - [POSIX]
59///  - [Linux]
60///
61/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html
62/// [Linux]: https://man7.org/linux/man-pages/man2/kill.2.html
63#[inline]
64#[doc(alias = "kill")]
65pub fn test_kill_process(pid: Pid) -> io::Result<()> {
66    backend::process::syscalls::test_kill_process(pid)
67}
68
69/// `kill(-pid, 0)`—Check validity of pid and permissions to send signals to
70/// all processes in the process group, without actually sending any signals.
71///
72/// # References
73///  - [POSIX]
74///  - [Linux]
75///
76/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html
77/// [Linux]: https://man7.org/linux/man-pages/man2/kill.2.html
78#[inline]
79#[doc(alias = "kill")]
80pub fn test_kill_process_group(pid: Pid) -> io::Result<()> {
81    backend::process::syscalls::test_kill_process_group(pid)
82}
83
84/// `kill(0, 0)`—Check validity of pid and permissions to send signals to the
85/// all processes in the current process group, without actually sending any
86/// signals.
87///
88/// # References
89///  - [POSIX]
90///  - [Linux]
91///
92/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html
93/// [Linux]: https://man7.org/linux/man-pages/man2/kill.2.html
94#[inline]
95#[doc(alias = "kill")]
96pub fn test_kill_current_process_group() -> io::Result<()> {
97    backend::process::syscalls::test_kill_current_process_group()
98}