0
votes
sigset_t new,old;


sigemptyset(&new);
sigaddset(&new, SIGINT); 
sigaddset(&new, SIGTSTP);
sigprocmask(SIG_BLOCK, &new, &old);
//Before son

(exec,(other stuff...))

// ON Father
sigprocmask(SIG_UNBLOCK, &new, &old);
sigprocmask(SIG_SETMASK, &old, NULL); 

I'm doing a project, being this, a shell program. I have already finished the first part of the project which is the use of pipes, forks, exec, I/O files. Now I'm crashing my project in order to find bugs and I came with this one that has become very annoying to me, because I can't find the solution. Sorry, but I cant post all my code here, because it might be copied by my classmates.

Looking at the code above, If I execute my program and spam the CTRL Z and CTRL C, right at the beginning of execution without inserting any command, my handler will enter in action saying that the program cant be suspended or paused, and if I write a new command being this,"sleep 5", and spam again, it is in a status of "ignore" because of the sigset_t , after the command finishes it gives me the messages of the handler, because "sleep 5" suspends everything, and is waiting for me to insert a new command, if I spam again my handler doesn't give any message when it should. It like the signals that I added are still blocked. Does SIG_UNBLOCK unblocks the whole set of signals that I added or just one?

1
"Sorry, but I cant post all my code here, because it might be copied by my classmates.", pffffffffffffff. "my handler will enter in action saying that the program cant be suspended or paused", what handle you block the signal !, "Does SIG_UNBLOCK unblocks the whole set of signals that I added or just one?", looking doc... man7.org/linux/man-pages/man2/sigprocmask.2.html... "The signals in set are removed from the current set of blocked signals." - Stargateur
by the way, sigprocmask(SIG_SETMASK, &old, NULL); undo your previous sigprocmask(SIG_UNBLOCK, &new, &old);... read the doc. - Stargateur
@Stargateur Thank you for your answer. I have understand the root of my problem - CodeOnce

1 Answers

0
votes

@Stargateur has found the root of my problem.

The correct code is:

sigset_t new,old;


sigemptyset(&new);
sigaddset(&new, SIGINT); 
sigaddset(&new, SIGTSTP);
sigprocmask(SIG_BLOCK, &new, &old);
//Before son

(exec,(other stuff...))

// ON Father
sigprocmask(SIG_UNBLOCK, &new, &old);