Linux Format

Controlling processes and using Unix signals

The subject of this tutorial is signal handling and working with processes in Rust. We’ll begin by showing how to spawn a new process in Rust – the relevant source file is named spawnNew.rs – without doing anything useful with it, just to show you the simplest form of process spawning. So, the logic of spawnNew.rs is found in the following code excerpt:

All of the work is done by the call to Command ::new() and the use of spawn() . As you might recall from the previous Rust tutorials, the expect() part is executed in case of error. As a reminder, you can replace expect() with unwrap(), but in that case you’re not going to be able to print your own error message.

The screenshot (right) shows part of the code of spawnNew.rs that contains multiple variations of Command::new() that show how to pass arguments to Command::new() and how to set the current directory. You can learn more details about std::process::Command at https://doc.rust-lang.org/std/process/struct.Command.html.

Running generates the output shown in the screenshot (). What’s important in the output is the fact that the error message from the last Command::new() call is printed before the Command::new() call with the .arg(“/doesNotExist”) parameter. This means that currently, we can’t be sure about the order

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format2 min read
OBS Studio
Version: 30.0.2 Web: https://obsproject.com There are lots of good options for recording screencasts, but if you want to live-stream T your desktop, one of the best options is OBS Studio. The app works with all the major online streaming providers, s
Linux Format1 min read
Wine For Wayland
2023 was a great year for the Wayland driver for Wine. The goal was to move forward from the experimental phase and make the driver a proper upstream component. A year later, after several merge requests, many people are now already able to use the l
Linux Format2 min read
Back Issues Missed One?
ISSUE 313 April 2024 Product code: LXFDB0313 In the magazine Discover how to use the ultimate hacker’s toolkit, staying out of trouble while doing so. And join us as we take the Puppy Linux developer’s new distro for a run and explore its container

Related