Terminate child processes on ctrl-c

0

1

In tiny core linux, I have the following script:


#!/bin/sh
# ~/.X.d/freerdp.sh

rdp(){
while true
do
xfreerdp -f [IP Address]
done
}

rdp &

It's pretty simple; when X starts up and checks the .X.d directory (as is the case in tiny core) it finds and executes this script. The script starts up freerdp and keeps a connection open to the server by restarting it whenever it closes. As you can see from the rdp & line, the function is run in the background to allow X to continue its startup routine.

The problem is that whenever I cancel X with a CTRL+ALT+BACKSPACE the rdp process doesn't die.

I'm looking for a way to kill the process as soon as X finishes, either through:

A) a script, executed on X closing, which kills the process or B) by modifying the script to check the return value of the xfreerdp command.

NB - if the solution does check the return value, it must only end if the command fails to open the X display. For that reason, if you could point me to a reference for xfreerdp return values I'd be grateful.

jackweirdy

Posted 2012-06-25T15:13:53.057

Reputation: 754

Does Ctrl+Alt+Backspace actually terminate the X process (and another process restarts it), or does it do a soft restart? – Darth Android – 2012-06-25T15:51:08.347

It fully terminates X. That is to say that if I run startx from the shell, waiting for X to start and pressing CTRL+ALT+BACKSPACE means the X display closes and the shell resumes. Also note that the shell I refer to is the only TTY on the system. – jackweirdy – 2012-06-25T15:57:17.640

Answers

0

In the end I solved this by changing the code to this:

#!/bin/sh
# ~/.X.d/freerdp.sh

while true
do
xfreerdp -f [IP Address]
done

Ugly, and I had to reorganise the order of script execution so this one ran last, but it kinda works...

jackweirdy

Posted 2012-06-25T15:13:53.057

Reputation: 754

0

See if this helps

It seems this question is already answered.

0xAF

Posted 2012-06-25T15:13:53.057

Reputation: 659

Wouldn't that rely on the process to be waiting though? – jackweirdy – 2012-06-25T18:09:00.703

Yes, of course, I missed the point here. But now that you mentioned it, why not remove the '&' (send to background) from the "rdp &" line, and leave it on foreground, this way when X terminates your script will get killed (with it's children too). – 0xAF – 2012-06-25T18:22:07.290

there are scripts that the X service runs afterwards - it would be possible to change the order of script execution but it would take a lot more time & testing. – jackweirdy – 2012-06-25T18:58:57.490