signals related question


 
Thread Tools Search this Thread
Top Forums Programming signals related question
# 1  
Old 02-13-2007
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
# 2  
Old 02-13-2007
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 Smilie

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.
# 3  
Old 02-13-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Question related to grep

We have huge file with control A as delimiter. Somehow one record is corrupted. This time i figured it out using ETL graph. If future , how to print only bad record. Example Correct record:... (2 Replies)
Discussion started by: srikanth38
2 Replies

2. Shell Programming and Scripting

awk related question

awk -F ";" 'FNR==NR{a=$1;next} ($2 in a)' server.list datafile | while read line do echo ${line} done when i run the above, i get this: 1 SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net .... instead of: SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net .... can... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. UNIX for Dummies Questions & Answers

Question related to 'ps'

If I run a script called 'abc.sh' and then execute the following : ps -ef | grep 'abc.sh' I always get two rows of output, one for the executing script, and the other for the grep command that I have triggered after the pipe. Questions: Why does the second row turn up in the results. My... (10 Replies)
Discussion started by: jawsnnn
10 Replies

4. Shell Programming and Scripting

Perl related question

hi, iam perl begginer,i have written the program #!/usr/bin/perl #use warnings; use strict; print "Enter the name:","\n"; my $name=<STDIN>; my %hash=(siva => "9902774481", dev => "9916391244", venky => "9440506760", manohar => "9440232695" ); print "$name no is:... (5 Replies)
Discussion started by: siva.hardwork
5 Replies

5. Shell Programming and Scripting

awk related question

awk "/^<Mar 31, 2012 : /,0" /app/blah.log can someone please help me figure out why the above command isn't pulling anything out from the log? basically, i want it to pull out all records, from the very first line that starts with the date "Mar 31, 2012" and that also has a time immediately... (4 Replies)
Discussion started by: SkySmart
4 Replies

6. Shell Programming and Scripting

A question about signals in Unix

Whats a signal 0. An exhaustive search on signals landed me nowhere. Is it possible to do something like this trap "echo $var" 0. If so what signal does this trap catch ? (2 Replies)
Discussion started by: kinny
2 Replies

7. Shell Programming and Scripting

Question using signals in my own shell..

Wasn't really sure where to put this, since I'm using C in UNIX, but I am making my own shell... so, what's going on is this: For our program, we had to create our own shell, and if the user pressed ctrl-c just at the cmdline, then this signal would be ignored, but if there is a foreground... (1 Reply)
Discussion started by: blind melon
1 Replies

8. UNIX for Advanced & Expert Users

One Question related to alias

Hello, I have created following alias in csh lab 'rlogin -l user23 complab23' but problem is complab23 does not allow automatic login by checking .rhosts file. So after typing lab on command line I have to type complicate password and if wrong password is typed thrice then account gets... (4 Replies)
Discussion started by: neerajrathi2
4 Replies

9. Programming

Unix/Linux Newbie(ish) Question - IPC/Signals

:) Hello, i have been given the following code to help me learn how to use signals, it won't compile. The problem maybe because this was written for use in Unix and i am trying to compile in Linux. The error i get says that SIGPIPE and SIG_IGN are undeclared. I think that these are defined... (2 Replies)
Discussion started by: theultimatechuf
2 Replies

10. UNIX for Dummies Questions & Answers

A Question related to the net

well, I was suggested to remove the contents of the cache as i get out of the browser netscape from the .netscape folder. is that really necessary? if so what are the rest to be done? can anybody please tell me?:rolleyes: (8 Replies)
Discussion started by: sskb
8 Replies
Login or Register to Ask a Question