Hi,
Does anyone know how to prevent from delivering signal to process even after that signal was unblocked?
Hi,
Does anyone know how to prevent from delivering signal to process even after that signal was unblocked?
you could catch it and do nothing with it
Code:signal(SIGINT, my_sigint_handler); ... void my_sigint_handler(int sig) { /* just return. do nothing here */ return; /* not really necessary, but just for clarity */ }
Thanks for your reply,
of course, I can block the signal, but this signal can't be blocked all the time. After definited time it should be unblocked.
Your requirements are not clear enough to suggest any specific solution.
If you want to check pending signals every X seconds, for instance, then you can set up an alarm to go off after X seconds, then in the signal handler for this alarm, unblock the signals of interest. If signals are pending, they will immediately be delivered. Once they are delivered, you can block them again and set up a new timer.
But without knowing more about your specific requirements that's as far as I can go.
I have to stop application by sending signal to it. During application is stopped user shouldn't be able to sent any other signals to that application (other signals must be blocked). User can resume program by sending another signal to it. When program is running all signals must be unblocked. Signals which was sent when application was stopped can't be delivered when application is running
No, in this task I have to use signals rather than IPC...
This sounds like when the app is in the "stopped" state, it's not really stopped, just doing nothing and ignoring all signals. If the application is truly stopped, there is no way to cause the signals which are delivered to it to be ignored -- they are simply deferred until the application starts again.
So when you enter your stop state, you should:
1. Unblock all signals and set their handlers to the ignore handler (SIG_IGN)
2. Enter an infinite loop calling pause()
Then, when the application is "unstopped:"
1. Break the infinite loop
2. Restore all signal handlers and masks to their original state
You can't make a signal just "vanish." It is either blocked (and will be delivered once unblocked), or ignored.
is there a specific reason why IPC is not an viable option? is this a school assignment of some sort where you are supposed to be learning about unix signals? I would think that IPC would be ideal for your application, as it allows programs to communicate with, or "signal" one another.
OK this problem is solved, but i have another one. How can I clear stdin buffer?
I know that i can use function like this:
but it works in case when in buffer is only one line. How to clean in when it's more than one line?Code:void dump_line( FILE * fp ) { int ch; while( (ch = fgetc(fp)) != EOF && ch != '\n' ) /* null body */; }