nc
Execute system call directly. nc
do not depend on std
.
Usage
Add this to Cargo.toml
:
[dependencies]
nc = "0.3.3"
And add this to crate code:
extern crate nc;
Examples
Get file stat:
let mut statbuf = nc::stat_t::default();
match nc::stat("/etc/passwd", &mut statbuf) {
Ok(_) => println!("s: {:?}", statbuf),
Err(errno) => eprintln!("Failed to get file status, got errno: {}", errno),
}
Fork process:
let pid = c::fork();
match pid {
Ok(pid) => {
if pid == 0 {
println!("parent process!");
} else if pid < 0 {
eprintln!("fork() error!");
} else {
println!("child process: {}", pid);
let args = [""];
let env = [""];
match nc::execve("/bin/ls", &args, &env) {
Ok(_) => {},
Err(errno) => eprintln!("`ls` got err: {}", errno),
}
}
},
Err(errno) => eprintln!("errno: {}", errno),
}
Kill self:
let pid = nc::getpid();
let ret = nc::kill(pid, nc::SIGTERM);
println!("ret: {:?}", ret);
Related projects
License
This library is release in Apache License.