- extern crate libc;
- use libc::*;
- unsafe fn test() {
- let pid = fork();
- if pid == 0 {
- // With libc 2.0, doing a kill -STOP <child_pid> will cause
- // the WIFSIGNALED to eval as true
- sleep(200);
- }
- else
- {
- println!("Parent and the child pid, run: kill -STOP {}", pid);
- // Do while, not pretty but works
- while {
- let mut status: i32 = 0;
- let status_ptr: *mut i32 = &mut status;
- let ret = waitpid(pid, status_ptr, WUNTRACED | WCONTINUED);
- println!("We have waited as the parent, for the child to die!");
- if ret == -1 {
- println!("Error");
- exit(1);
- }
- if WIFEXITED(status) {
- println!("Exited, status: {}", WEXITSTATUS(status));
- }
- else if WIFSIGNALED(status) {
- println!("Killed by signal: {}", WTERMSIG(status));
- }
- // kill -STOP child_pid should hit here but hits WIFSIGNALED ^
- else if WIFSTOPPED(status) {
- println!("Stopped by signal: {}", WSTOPSIG(status));
- }
- !WIFEXITED(status) && !WIFSIGNALED(status)
- } {}
- }
- }
- fn main() {
- unsafe { test(); }
- }
Running this, then kill -STOP <child_pid> causes WIFSIGNALED to eval as true.