You are not logged in.

#1 2012-09-28 22:34:18

tladuke
Member
Registered: 2009-07-23
Posts: 171

replace fgets with what in main loop of pthread c program?

I'm modifying this program. It starts some pthreads and then does (in main)

...
while(1){

                fgets(line,75,stdin);
                if(line[0] == 'q' || line[0] == 'Q')
                        break;

}
exit_flag = 1;
pthread_cancel(foo_thread);

I want to be able to background this program and have it respond to SIGTERM etc. Right now it will only quit while backgrounded if I do SIGKILL. Is there something I can just throw in place of fgets? or do I need to do a little rewrite? I don't need any keyboard input. I'm trying to make it a daemon.

Last edited by tladuke (2012-09-28 22:38:16)

Offline

#2 2012-09-29 10:24:05

SahibBommelig
Member
From: Germany
Registered: 2010-05-28
Posts: 80

Re: replace fgets with what in main loop of pthread c program?

You could look into the pause(3) call.

(And write a signal handler that responds to the signals you want)

Last edited by SahibBommelig (2012-09-29 10:24:52)

Offline

Board footer

Powered by FluxBB