Running a Rust program in background

I have a Rust program called gpio-alarm that takes a time as an argument, waits for that time, then triggers an arbitrary event on GPIO. I'd like this program to run in the background when I run gpio-alarm in the terminal, but currently, I have to run gpio-alarm &. It is not meant to run at startup or anything, so I don't know if it should be a daemon.

Thanks for your time!

that's just how the os works,i think you can make so the program starts an invisible copy of itself and immediately closes the visible one

AFAIK you can call Command::spawn from a thin second binary to spawn the actual gpio-alarm as a detached child process, to emulate the ampersand. If you only want to support Unix-like operating systems, the fork crate might also be of interest to you.

1 Like