Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

catching a signal !

Posted on 2000-02-16
5
Medium Priority
?
746 Views
Last Modified: 2008-03-06
I want to catch the SIGINT signal without using the pause( ) call in
my program.Basically I should be able to catch a signal without having
to wait for the signal to occur. My signal handler should get executed
whenever the signal gets delivered to my process.

Currently I have to use pause(. )

Is there a way out...

Kindly let me know.

Regards,
arut
0
Comment
Question by:arut
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 150 total points
ID: 2531773
Yep, you need to register a signal handler to catch the exception. Take a look at the man pages for signal() and sigaction() and friends.
0
 

Expert Comment

by:montenegro
ID: 2533268
It is easy to catch a signal without pause(), like this:

use the function "signal" to install a signal handler ( a function made by you that is called when your process receives a certain signal), in your case:

signal(SIGINT, handler);

where "handler" is a function made by you with this aspect (it can have any other name):

void handler(int signo)
{
      here you do whatever you whant to do when SIGINT is catched...

}

signo is the number of the signal that called this handler , in your case SIGINT.

try it...
            montenegro.
0
 

Author Comment

by:arut
ID: 2533935
I have registered a signal handler but the handler does
not get executed because the signal itself does not
get delivered unless the program has a pause( )

All I want is ...

signal(SIGINT,handler);

do some processing...

if signal has come the handler gets executed automatically


-------------------------------------------

I don't want to use a pause( ), which suspends the process till the signal is received.

If I wait for the signal I can't do other work in the program...

Whenevr the signal comes handler should be executed.
Currently I am not able to do this without pause ( ).
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2535133
Well, then it may not be coded correctly. The following is a little demonstration program that works:

cat >gork.c <<EOF
#include <stdio.h>

void catcher()
{
  printf("Caught SIGINT\n");
  exit(1);
}
#include <signal.h>

main()
{
  /*
   * Register my signal handler
   */
  signal(SIGINT, &catcher);
  (void) getchar();
  printf("Normal exit\n");
  exit(0);
}
EOF

Compile it and run it. It'll wait for either something to be typed at the keyboard or a SIGINT to be delivered.
0
 

Expert Comment

by:abhishekpatel
ID: 2584569
use the following

signal(SIGINT,sig_catch);

 when SIGINT event occurs the function named "sig_catch" will be
executed. so keep the code inside the sig_catch function which must me executed when SIGINT occurs.
         here u can do other work when the SIGINT occurs it executes the sig_catch function.u need not have to use pause.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question