Skip to content

Commit 986a003

Browse files
committed
feat: Add killpg
1 parent a2fa282 commit 986a003

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
### Added
88
- Add IP_RECVIF & IP_RECVDSTADDR. Enable IP_PKTINFO and IP6_PKTINFO on netbsd/openbsd.
99
([#1002](https://github.com/nix-rust/nix/pull/1002))
10+
- Add killpg
11+
([#1034](https://github.com/nix-rust/nix/pull/1034))
1012
### Changed
1113
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))
1214
- `recvmsg` now returns an Iterator over `ControlMessageOwned` objects rather

src/sys/signal.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,22 @@ pub fn kill<T: Into<Option<Signal>>>(pid: ::unistd::Pid, signal: T) -> Result<()
680680
Errno::result(res).map(drop)
681681
}
682682

683+
/// Send a signal to a process group [(see
684+
/// killpg(3))](http://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html).
685+
///
686+
/// If `pgrp` less then or equal 1, the behavior is platform-specific.
687+
/// If `signal` is `None`, `killpg` will only preform error checking and won't
688+
/// send any signal.
689+
pub fn killpg<T: Into<Option<Signal>>>(pgrp: ::unistd::Pid, signal: T) -> Result<()> {
690+
let res = unsafe { libc::killpg(pgrp.into(),
691+
match signal.into() {
692+
Some(s) => s as libc::c_int,
693+
None => 0,
694+
}) };
695+
696+
Errno::result(res).map(drop)
697+
}
698+
683699
pub fn raise(signal: Signal) -> Result<()> {
684700
let res = unsafe { libc::raise(signal as libc::c_int) };
685701

test/sys/test_signal.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ fn test_kill_none() {
99
kill(getpid(), None).expect("Should be able to send signal to myself.");
1010
}
1111

12+
#[test]
13+
fn test_killpg_none() {
14+
killpg(getpgrp(), None)
15+
.expect("Should be able to send signal to my process group.");
16+
}
17+
1218
#[test]
1319
fn test_old_sigaction_flags() {
1420
extern "C" fn handler(_: ::libc::c_int) {}

0 commit comments

Comments
 (0)