Execute system call directly. nc do not depend on std.
Add this to Cargo.toml:
toml
[dependencies]
nc = "0.7"
Get file stat:
rust
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:
rust
let pid = nc::fork();
match pid {
    Ok(pid) => {
        if pid == 0 {
            println!("child process: {}", pid);
            let args = [""];
            let env = [""];
            match nc::execve("/bin/ls", &args, &env) {
                Ok(_) => {},
                Err(errno) => eprintln!("`ls` got err: {}", errno),
            }
        } else if pid < 0 {
            eprintln!("fork() error!");
        } else {
            println!("parent process!");
        }
    },
    Err(errno) => eprintln!("errno: {}", errno),
}
Kill self:
rust
let pid = nc::getpid();
let ret = nc::kill(pid, nc::SIGTERM);
// Never reach here.
println!("ret: {:?}", ret);
Or handle signals: ```rust fn handlealarm(signum: i32) { asserteq!(signum, nc::SIGALRM); }
fn main() { let ret = nc::signal(nc::SIGALRM, handlealarm as nc::sighandlert); assert!(ret.isok()); let remaining = nc::alarm(1); let ret = nc::pause(); assert!(ret.iserr()); asserteq!(ret, Err(nc::EINTR)); asserteq!(remaining, 0); } ```
For stable version of rustc, please install a C compiler (gcc or clang) first.
As asm! feature is unavailable in stable version.
Current work is focused on linux networking. FreeBSD and other OS are unavailable yet.
This library is release in Apache License.