c - User defined signal message -
so, i'm using signals project, , i'm getting not error think.
i'll explain, got code, sr2 global variable triggered signal sigusr2 , signal handling working fine. compile , run, , when trigger sigusr2, prints "user defined signal 2" , stops.
i have code in while(1) loop , it's not supposed stop. can fix problem printting something, printf commented, keeps printing forever, , can't make new inputs, trigger other signals.
int teste( const char* path , const char* cadeia, const char* erro ) { int i, x, stat; int fd = open( path, o_wronly | o_creat , s_irusr | s_iwusr | s_ixusr | s_irgrp | s_iwgrp | s_ixgrp | s_iroth | s_iwoth | s_ixoth ); x = flock(fd, lock_ex); if ( sr1 ) { printf("sr1\n"); //sr1 = !sr1 ; } if ( !sr2 ) { ( i=0 ; i<cadeias ; i++ ) { stat = write( fd, cadeia, strlen(cadeia)); } } else { printf("\n"); ( i=0 ; i<cadeias/2 ; i++ ) { stat = write( fd, cadeia, strlen(cadeia)); stat = write( fd, erro, strlen(erro)); } } if ( stp ) { printf("gtfo\n"); } x = flock(fd, lock_un); close(fd); return 0 ; }
this called in "thread maker":
void * threadescritor() { int ; char *f, *c, *e ; f = (char *)malloc(sizeof(sizeficheiro)); c = (char *)malloc(sizeof(sizecadeia)); e = (char *)malloc(sizeof(sizecadeia)); while(1) { = randomnum(4); f = pickfile(a, f); = randomnum(9); c = pickchar(a, c); e = pickerror(a, e); //escreve1x(f, c, e); teste(f, c, e); if(stp) { break; } } pthread_exit(0); }
which called in main:
int main () { pthread_t tids[num_threads]; int i, safe ; void* resultado; sr1 = false ; sr2 = false ; stp = false ; signal( sigusr1, sighandler ); signal( sigusr2, sighandler ); signal( sigtstp, sighandler ); ( i=0; i<num_threads ; i++ ) { safe = pthread_create( &(tids[i]) , null , threadescritor ) ; if ( safe != 0 ) perror ("error creating threads"); } ( i=0; i<num_threads ; i++ ) { safe = pthread_join( tids[i], &resultado ) ; if ( safe != 0 ) { perror ("errors waiting"); } } }
so wondering why message showing (since i'm not printing anywhere) , why stops while(1) loop, , why if make printf() "solves" problem.
Comments
Post a Comment