The problem is caused because the program you run has the terminal set to the terminal of the parent shell. When that terminal is closed, SIGHUP (the hang-up signal) is sent to all processes which are attached to the terminal, and presumably your program chooses the default action for this signal, which is to terminate.
There are several solutions. I list them here is order of easy of implementation/use, easiest first:
- Prefix the command with "nohup". This traps SIGHUP, protecting your program from it. Output of the program will be send to the file "nohup.out". See the nohup manual page for further details.
- Run your program in GNU Screen. This takes a little more learning, but it's well worth it. For example, you can detach a process from a terminal, and re-attach it to another. The screen manual page is a little turgid, but worth a read. You might also find this tips page useful.
- Alter your program to run as a proper daemon process as opposed to a regular process which is backgrounded using shell job control. There's more to running as a daemon then just ignoring SIGHUP. See here for details.