Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have written a Ruby script to manage my LyX documents. The script has a short CLI interaction with the user(=me), and then it decides the name of the file to open, and opens it via a lyx shell command.

Now, the problem is, I need a terminal for the CLI interaction, but when I close the terminal, LyX pops a message box that says "SIGHUP signal caught! Bye." and when I click on OK, it closes LyX.

That problem occurred when I launched the shell via Ruby's exec command(that closes the ruby process and starts a new process for the given shell command). When I tried to replace it with a fork, the LyX windows never opened - my guess was that LyX received the SIGHUP when the Ruby script finished and the terminal closed - and I confirmed that guess when I added a gets command at the end of the Ruby script to prevent it from closing - and then the LyX window was opened, but when I pressed Enter to finish the ruby script, LyX received the SIGHUP and closed.

Now, I can probably solve this by replacing the CLI interaction with a GUI and giving up on the terminal window, but using a GUI for something like that seems like an overkill to me. So, is there a way to prevent LyX from closing when I close the terminal?

I'm running OpenSUSE 12.1 64bit with KDE, and the terminal emulator is Konsole.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

One option is to run it with nohup:

nohup mycoollittlescript

Another would be to run it inside a terminal emulator like tmux or screen. These are terminal apps that are themselves terminal emulators. When the parent terminal is closed, they stay running in the backgrounmd and tyou can reconnect to them from another terminal window. Try this:

screen -R -d NameOfMyBackgroundJob

The first time this will create a new session. Repeated uses of the above command will connect to the existing session and disconnect it from any other terminal windows.

share|improve this answer
    
Thanks! The nohup solution worked! Though for some reason, it only works when I fork it from Ruby. If I try it directly from bash it doesn't work... –  Idan Arye Mar 4 '12 at 0:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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