🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Running a process (job) in background.

Started by
5 comments, last by Code Alchemist 17 years, 10 months ago
I know how to run a job in the background, but when I type the 'bg' command, and then 'jobs', it still says the process is stopped. What do I need to do, probably to my program, to keep in running in the background?
Advertisement
Maybe the hangup signal terminates your program? See man nohup.
I tried nohup, and it still didn't work.
Try "nohup command &"
If your application is mainly intended to be run in the background, it might be a good idea to do this from code instead of from the shell. The following piece of code will fork the process to break it loose from the terminal that started it, and effectively run it even more in the background than running it with 'bg' would, since killing the shell won't kill the process:
#include <unistd.h>int main(){    /* fork the process, kill the parent */    if(fork())        return 0;    /* do stuff here; the process is now free of the terminal that started it */    return 0;}


Of course, if you don't usually want to run your program in the background, or if you want to use your shell's job control, then this isn't a very good solution.
Actually, I used screen, and it worked!
Have you tried to use the set -b feature to see when your apps is stopped.
May be it's trying to read from ( write to ) the terminal.[ from the bash Info ] Background processes which attempt to read from (write to) the terminal are sent a `SIGTTIN'(`SIGTTOU') signal by the terminal driver, which, unless caught,suspends the process.
So what about trying to do some signal handlings inside your app.

This topic is closed to new replies.

Advertisement