![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| One Question related to alias | neerajrathi2 | UNIX for Advanced & Expert Users | 4 | 01-24-2008 01:43 AM |
| a math related question | jahjah | Shell Programming and Scripting | 9 | 09-13-2004 07:56 AM |
| 1st post here! directory related question ( // )... | MrOrange | UNIX for Dummies Questions & Answers | 2 | 06-26-2002 06:21 PM |
| Unix/Linux Newbie(ish) Question - IPC/Signals | theultimatechuf | High Level Programming | 2 | 01-20-2002 07:38 PM |
| A Question related to the net | sskb | UNIX for Dummies Questions & Answers | 8 | 10-03-2001 06:37 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
signals related question
Hi all,
Just a little question relative to signals. I know that if an application is in the sleep state, When a signal is catched, it will be processed by the handler. But what happens if it's processing something? Does the processing stops?? The following code should illustrate this case void handleSignal(int signal){ while(my_object->getWorkingState==1) sleep(1); printf("anything"); } int main(...){ .... signal(SIGUSR1,handleSignal); while(1){ my_object->process(); sleep(); } .... } Thanks for the attention. Best regards, Ernesto |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
take this example program Code:
#include <stdio.h>
#include <signal.h>
void process(void);
void sigFunc(int);
void sigFunc(int sigNo) {
printf("Received Signal: %d\n", sigNo);
exit (1);
}
void process() {
//Run it with printf uncommented and sleep commented
//For the second time do the vice-versa
//printf("What am I doing\n");
sleep(1);
}
int main()
{
signal(SIGUSR1, sigFunc);
while (1) {
process();
}
return 0;
}
If you do run the program in two different ways, where printf is active, therefore its processing and in the second form where it is in sleep mode, thereby after executing the sleep call in either of the case, whatever be the state of the program that is in memory when kernel delivers a signal to the process, if the signal handler is registered with a function 'f' it would be executed else default action of the delivered signal would be executed. |
|
|||
|
If your question is what I think it is, if your proccess is within a system call or a library call, the signal can stop that call, and the call will return an error usually. Then you can check if the SIGALRM was set (or set through your own signal handler function) to decide what to do next.
|
|||
| Google The UNIX and Linux Forums |