26 releases

0.5.1 Nov 9, 2020
0.4.13 Aug 28, 2020
0.4.12 Jul 14, 2020
0.4.10 Mar 29, 2020
0.1.0 Jul 26, 2019

#48 in Operating systems

Download history 43/week @ 2020-08-05 47/week @ 2020-08-12 37/week @ 2020-08-19 52/week @ 2020-08-26 113/week @ 2020-09-02 20/week @ 2020-09-09 14/week @ 2020-09-16 42/week @ 2020-09-23 23/week @ 2020-09-30 25/week @ 2020-10-07 10/week @ 2020-10-14 30/week @ 2020-10-21 52/week @ 2020-10-28 28/week @ 2020-11-04 17/week @ 2020-11-11 9/week @ 2020-11-18

159 downloads per month
Used in 2 crates

Apache-2.0

2MB
45K SLoC

nc

Build Status Latest version Documentation Minimum rustc version License

Execute system call directly. nc do not depend on std.

Usage

Add this to Cargo.toml:

[dependencies]
nc = "0.5"

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 = nc::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);
// Never reach here.
println!("ret: {:?}", ret);

Stable version

For stable version of rustc, please install a C compiler (gcc or clang) first. As asm! feature is unavailable in stable version.

Related projects

License

This library is release in Apache License.

No runtime deps