The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-2007
Registered User
 

Join Date: Nov 2006
Posts: 5
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-13-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,573
Quote:
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?
Not so, really

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.
Reply With Quote
  #3 (permalink)  
Old 02-13-2007
Registered User
 

Join Date: Feb 2007
Location: Israel
Posts: 22
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0