-
Notifications
You must be signed in to change notification settings - Fork 479
/
Copy pathsig_simple2.rs
43 lines (37 loc) · 1 KB
/
sig_simple2.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![no_std]
#![no_main]
extern crate user_lib;
use user_lib::*;
fn func() {
println!("user_sig_test passed");
sigreturn();
}
#[no_mangle]
pub fn main() -> i32 {
let pid = fork();
if pid == 0 {
let mut new = SignalAction::default();
let mut old = SignalAction::default();
new.handler = func as usize;
println!("signal_simple2: child sigaction");
if sigaction(SIGUSR1, Some(&new), Some(&mut old)) < 0 {
panic!("Sigaction failed!");
}
sleep(1000);
println!("signal_simple2: child done");
exit(0);
} else if pid > 0 {
println!("signal_simple2: parent kill child");
sleep(500);
if kill(pid as usize, SIGUSR1) < 0 {
println!("Kill failed!");
exit(1);
}
println!("signal_simple2: parent wait child");
let mut exit_code = 0;
waitpid(pid as usize, &mut exit_code);
println!("signal_simple2: parent Done");
exit(0);
}
0
}