mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-24 10:26:25 +04:00
add user app: forkexec.rs, update hello_world.rs
This commit is contained in:
parent
07bdb0ce7e
commit
3bc09a651e
27
user/src/bin/forkexec.rs
Normal file
27
user/src/bin/forkexec.rs
Normal file
@ -0,0 +1,27 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, getpid, wait, exec};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
println!("pid {}: parent start forking ...", getpid());
|
||||
let pid = fork();
|
||||
if pid == 0 {
|
||||
// child process
|
||||
println!("pid {}: forked child start execing hello_world app ... ", getpid());
|
||||
exec("hello_world");
|
||||
100
|
||||
} else {
|
||||
// parent process
|
||||
let mut exit_code: i32 = 0;
|
||||
println!("pid {}: ready waiting child ...", getpid());
|
||||
assert_eq!(pid, wait(&mut exit_code));
|
||||
assert_eq!(exit_code, 0);
|
||||
println!("pid {}: got child info:: pid {}, exit code: {}", getpid() , pid, exit_code);
|
||||
0
|
||||
}
|
||||
}
|
@ -4,8 +4,10 @@
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{getpid};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
println!("Hello world from user mode program!");
|
||||
println!("pid {}: Hello world from user mode program!", getpid());
|
||||
0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user