2

I have the following script, which starts X and launches a graphical program:

#!/bin/sh
#startGraphics.sh 
#Starts X and runs the graphics program

xinit /opt/common/graphics/bin/launchGraphics.sh &
sleep 10 ; 
echo "Successfully launched graphics program!"

I added the sleep and echo because if I simply ran the script, it would kill X and the graphics program immediately as the SSH session closed. The problem is, although the sleep and echo make X and the graphics program start, the SSH session does not end.

However, if I manually SSH'd into the machine, then ran the startGraphics.sh script, then exited the SSH session once the X server and program started, they would continue to run, and the SSH session would not hang.

What am I doing wrong here? What is the correct way to do what I am attempting, i.e. how do I start X remotely with the graphics program and have the SSH session complete without hanging and without X immediately terminating?

Though I don't think it relevant to the problem, here is the launchGraphics.sh script, just in case:

#!/bin/sh
#launchGraphics.sh
#Starts the graphics program. Requires X to be running
xrandr -s 1920x1050 ;
/opt/common/graphics/bin/graphics --position 0,0 --mode 1 &
/opt/common/graphics/bin/graphics --position 100,0 --mode 2 &
/opt/common/graphics/bin/graphics --position 300,0 --mode 3 
  • This may be due to the child process receiving a signal when the non-interactive session ends. Try using nohup xinit /opt/common.... – alienth Sep 17 '15 at 19:52
2

The problem turned out to be redirection of stdout (and presumably stderr).

By adding > logfile.log 2>&1 & to the end of the xinit line, the SSH session closes out safely and the X session and graphics programs continue to run.

So the final startGraphics.sh looks like:

#!/bin/sh
#startGraphics.sh 
#Starts X and runs the graphics program

xinit /opt/common/graphics/bin/launchGraphics.sh > /dev/null 2>&1 &
sleep 10 ; 
echo "Successfully launched graphics program!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.