How to manage systems software
cargo buildLive demo using cargo build --timings
std::process modulefn main() -> Result<()> {
let mut cmd = Command::new("ls").spawn()?;
let status = cmd.wait()?;
match status.code() {
Some(code) => {
if status.success() {
println!("ls finished successfully with code {code}")
} else {
println!("ls failed with status code {code}")
}
}
None => {
println!("ls terminated by signal")
}
}
Ok(())
}lsfn main() -> Result<()> {
let mut cmd = Command::new("ls").spawn()?;
cmd.wait()?;
if let Some(mut stdout) = cmd.stdout.take() {
// `stdout` implements `Read`, so we can redirect to *our* stdout:
let mut buf = [0; 512];
while let Ok(count) = stdout.read(&mut buf)
&& count != 0
{
std::io::stdout().write_all(&buf[..count])?;
}
}
Ok(())
}stdin for passing data from the parent to the child processstdout for passing data from the child to the parent processstderr for passing diagnostic information from the child to the parent processstdout instead of stderr
| Method | Throughput | Latency | Ease of setup | Structured data | Sync complexity | Cross-language | Persistence | Security / Isolation |
|---|---|---|---|---|---|---|---|---|
| Anonymous pipes | + | ++ | ++ | - | + | ++ | - - | + |
| Named pipes (FIFO) | + | ++ | + | - | + | ++ | - | + |
| Unix domain sockets | ++ | ++ | + | - | + | ++ | - | ++ |
| Network sockets | ++ | + | + | - | + | ++ | - | - |
| Message queues (POSIX) | ++ | ++ | - | - | + | ++ | - | + |
| Shared memory | ++ | ++ | - - | - | - - | ++ | - | - |
| Memory-mapped files | ++ | ++ | - | - | - - | ++ | + | - |
| Files on disk | - | - - | ++ | - | - | ++ | ++ | - |
| RPC | + | + | + | ++ | + | ++ | - | ++ |
| Message passing | ++ | + | - | + | + | ++ | ++ | ++ |
| Signals | - - | ++ | ++ | - - | - - | + | - - | - |
| Threads | ++ | ++ | + | ++ | - - | - - | - - | - |
----l in ls -l)cp ./source ./destination)-m "message" in git commit -m "message" )KEY=value (e.g. RUST_LOG=info)fn main() {}
std::env:
std::env::args(): Iterator over command line args (strings)std::env::vars(): Iterator over environment variables (key-value pairs)clap are typically used