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