1. extern crate libc;
  2. use libc::*;
  3. unsafe fn test() {
  4. let pid = fork();
  5. if pid == 0 {
  6. // With libc 2.0, doing a kill -STOP <child_pid> will cause
  7. // the WIFSIGNALED to eval as true
  8. sleep(200);
  9. }
  10. else
  11. {
  12. println!("Parent and the child pid, run: kill -STOP {}", pid);
  13. // Do while, not pretty but works
  14. while {
  15. let mut status: i32 = 0;
  16. let status_ptr: *mut i32 = &mut status;
  17. let ret = waitpid(pid, status_ptr, WUNTRACED | WCONTINUED);
  18. println!("We have waited as the parent, for the child to die!");
  19. if ret == -1 {
  20. println!("Error");
  21. exit(1);
  22. }
  23. if WIFEXITED(status) {
  24. println!("Exited, status: {}", WEXITSTATUS(status));
  25. }
  26. else if WIFSIGNALED(status) {
  27. println!("Killed by signal: {}", WTERMSIG(status));
  28. }
  29. // kill -STOP child_pid should hit here but hits WIFSIGNALED ^
  30. else if WIFSTOPPED(status) {
  31. println!("Stopped by signal: {}", WSTOPSIG(status));
  32. }
  33. !WIFEXITED(status) && !WIFSIGNALED(status)
  34. } {}
  35. }
  36. }
  37. fn main() {
  38. unsafe { test(); }
  39. }

Running this, then kill -STOP <child_pid> causes WIFSIGNALED to eval as true.