User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

SOLVED: Assigning other signals like SIGUSR1 to keyboard

Sun Oct 20, 2013 12:49 pm

I'm essentially looking for the fewest keystrokes way to send a SIGUSR1 to an application - ideally from the same console the application is running.

Best solution would be to set up a console keystroke to send a SIGUSR1 to a blocking console application like Ctrl-C sends SIGINT. However I can't find anything from googling.

As an alternative I know I could go to a different console window, and use something along the lines of

Code: Select all

pkill -INT -f "python /home/pi/Downloads/drone.py"
Is there a way to assign that to a keystroke or is the only option to turn it into a 1 line bash script?

Any other suggestions?
Last edited by Hove on Sun Oct 20, 2013 1:27 pm, edited 1 time in total.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Assigning other signals like SIGUSR1 to keyboard

Sun Oct 20, 2013 1:12 pm

Create a script containing

sudo killall $1 -USR1

and then invoke the script.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Assigning other signals like SIGUSR1 to keyboard

Sun Oct 20, 2013 1:17 pm

Create a script containing

sudo killall $1 -USR1

and then invoke the script.
See .sig.

To the OP: Sometimes (as in this case), the answer is "No."

One way to achieve what (I think) you are trying to achieve might be to setup your app to respond to SIGQUIT (which is usually unused and available - the primary purpose of SIGQUIT is to generate core dump files). SIGQUIT can be generated from the keyboard (and the key bound to it can be set with "stty").
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: SOLVED: Assigning other signals like SIGUSR1 to keyboard

Sun Oct 20, 2013 1:40 pm

Problem solved but not by assigning other keyboard signals;

The underlying problem, which I tried to distill as much as possible to make the post as small as possible, is that my code uses subprocess.Popen to start up raspivid. Hitting Ctrl-C for my code is caught in a signal handler and does "stuff". Sadly, it's also passed to raspivid as my child, which stops videoing.

Hence this question was about changing the signal sent to my code to do "stuff" without stopping raspivid.

I couldn't daemonize it simply by setting the subprocess.Popen command line to end with "&" - it moaned at that.

But then I discovered the preexec_fn for subprocess.Popen which allowed me to call os.setpgrp() in the preexec_fn, thus separating raspivid from my code's group, and therefore Ctrl-C doesn't get forwarded to raspvid. I can still send raspivid SIGINT in my code when I want to stop the videoing by doing

Code: Select all

def daemonize():
        os.setpgrp()

raspivid_proc = subprocess.Popen(["raspivid", "-o", "video_file_name", "-t", "0"], preexec_fn = daemonize)

....

raspivid_proc.send_signal(signal.SIGINT)
Thanks for the suggested solutions to the distilled problem I described.
Last edited by Hove on Sun Oct 20, 2013 1:42 pm, edited 1 time in total.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

Return to “Raspberry Pi OS”