I have a device that connects via USB when a button is pressed. It immediately ceases the connection, when the button is released. I want to start a graphical application when I press this button.
I could successfully access the button and start the application. The problem is that when I press the button multiple times, the application restarts again and again after being closed, because udev apparently queues the events or holds them until they can be processed.
So I wrote a bash script that checks whether the application is running. When it is not running it starts the application. When it is running it maximizes the application. Here the same problem occurred, so I tried to start the application in the background with &
, but then it is killed when the udev rule has finished. Same with nohup
Maybe a bash script is not the best way here. I need a script that can start a long-term application in a separate process, so the script can finish and be run again. It should, if possible, also be a Linux native method, so I don't have to install more dependencies.
I found this thread How to run long time process on Udev event? that deals with the same problem. He appearently solved it with using cmd | at now
, but this commands seems to be deprecated, since cronie doesn't have this command like cron did.
I just found out that at is a package you need to install, but then the application also starts multiple times and the script doesn't finish.
I am running Manjaro, so basically Arch.
at
isn't part ofcron
, you just need to make sure it is installed and that theatd
daemon is running. Please [edit] your question and add your OS information if you need help with that. – terdon Sep 25 '20 at 13:13at
does also not solve the problem. I edited the description. – neolith Sep 25 '20 at 13:15flock
utility, e.g.flock -n /path/to/script /path/to/script
, if you don't want to have a "storm" of processes running your script at the same time. – Sep 25 '20 at 16:22man 1 flock
. If you an instance of your script to wait until the previous has finished, you're usingflock
without-n
. – Sep 27 '20 at 12:34