Problem with handling SIGINT


 
Thread Tools Search this Thread
Top Forums Programming Problem with handling SIGINT
# 1  
Old 02-24-2008
Problem with handling SIGINT

For a program I am designing, which involves handling the keyboard input Ctrl^c (SIGINT), it is taking ages for the program to actually recognise and perform the corresponding action whenever I run it and hit Ctrl^C at the CL. I have to do at least 3 Ctrl^Cs before the program will actually register and handle SIGINT appropriately.

Currently Im using signal() to map the various types of unix signals (i.e SIGINT, SIGSTSP) to handler functions I have defined in my program. What the handler functions do is call exit(0) (which quits the program) whenever the corresponding signal has been received by the program. As I mentioned before, it is taking several Ctrl^Cs to get the handler functions to be invoked, when it should just be 1 Ctrl^C.

Im unsure what could be causing my problem. Please feel free to make any suggestions.
# 2  
Old 02-24-2008
Please provide sample code so we can understand exeactly what you are doing.
# 3  
Old 02-24-2008
Ive actually solved my own problem, however I will still post up the code (sorry for not doing it earlier) and how I solved it for anyone who is interested

This is basically how I do my signal mapping

Code:
signal(SIGINT, SigHandler);
signal(SIGTSTP,SigHandler);

This is SigHandler()

Code:
void SigHandler()
{
  printf("Process terminating\n");
  exit(0);
}

A design requirement was for me to get the program to check under a network drive if a certain directory existed. To fulfill this requirement, I made my program call the find command from the shell via system(). When I was assembling the shell command, I put /mnt/ in front of the disk I wished to search.

Strangely enough, when I removed /mnt/ from the command string, the search time was reduced and the program ran a lot faster (It wasn't running as fast before). Unfortuntately though Ctrl^C was still not responding in the desired timespan, however Ctrl^Z (SIGTSTP) was. I ended up axing signal(SIGINT, SigHandler); altogether and my problem was solved.

At some point in the future, Id still like to be able to get Ctrl^C to respond a lot faster as using Ctrl^C to terminate a unix-based command or program is more well-known. I think that Ctrl^Z should still be reserved strictly for the suspending process
# 4  
Old 02-24-2008
That is controlled by the intr option of the mount command. From the mount_nfs(1m) man page:
Quote:
intr | nointr

Allow (do not allow) keyboard interrupts to kill a process that is hung while waiting for a response on a hard-mounted file system. The default is intr, which makes it possible for clients to interrupt applications that can be waiting for a remote mount.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Always pass SIGINT in ksh

The following command will run and wait for input from the user. /usr/sap/SAP/webdisp/wdispmon pf=/usr/sap/SAP/webdisp/profile What I would like to do is (in one command): - Add the above line to a ksh script - Receive the output - and send a SIGINT I have seen many posts on how to... (3 Replies)
Discussion started by: sapsid
3 Replies

2. Shell Programming and Scripting

problem handling lov in FOR loop

Hi all, i am trying to process a list of values in FILE like this: aaa:bbb ccc:ddd eee:fff With the following logic: for INFO in FILE do export F1=`cut -f1,3,5,7 -d":" < FILE` export F2=`cut -f2,3,5,7 -d":" < FILE` ssh $F1 bash <<EOF echo $F1 echo $F2 date (10 Replies)
Discussion started by: jonnyd
10 Replies

3. UNIX for Dummies Questions & Answers

SIGINT issue

May i know what are the possible causes for SIGINT other than ctrl-c? Thanks (17 Replies)
Discussion started by: pandeesh
17 Replies

4. Infrastructure Monitoring

Perl Error Handling Problem

I can get this working, but if something is down I get an error and the script does not move on. I can not get the "else" function working. What might I be doing wrong? use SNMP::Simple my %ios = (); $list="list.list"; open(DAT, $list) || die("Can't Open List"); @raw_data=<DAT>;... (4 Replies)
Discussion started by: mrlayance
4 Replies

5. Programming

problem in reforking and signal handling

hi friends i have a problem in signal handling ... let me explain my problem clearly.. i have four process .. main process forks two child process and each child process again forks another new process respectively... the problem is whenever i kill the child process it is reforking and the... (2 Replies)
Discussion started by: senvenugopal
2 Replies

6. Programming

problem in SIGSEGV signal handling

i wrote handler for sigsegv such that i can allocate memory for a variable to which sigsegv generated for illlegal acces of memory. my code is #include <signal.h> #include<stdio.h> #include<stdlib.h> #include<string.h> char *j; void segv_handler(int dummy) { j=(char *)malloc(10); ... (4 Replies)
Discussion started by: pavan6754
4 Replies

7. Programming

[C] fgets problem with SIGINT singlal!!!

Hi all, I have this method to read a string from a STDIN: void readLine(char* inputBuffer){ fgets (inputBuffer, MAX_LINE, stdin); fflush(stdin); /* remove '\n' char from string */ if(strlen(inputBuffer) != 0) inputBuffer = '\0'; } All work fine but if i... (1 Reply)
Discussion started by: hurricane86
1 Replies

8. Shell Programming and Scripting

Problem with awk while handling special charaters

Hi, I have an application.xml file like </dependency> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <context-root>oldvalue</context-root> <type>ear</type> <DOCTYPE "abc/xyz/eft"> <NewTag>value123</xyz> ... (4 Replies)
Discussion started by: subin_bala
4 Replies

9. UNIX for Dummies Questions & Answers

file handling problem in perl......

Hi, I am opening a file......then i am wrting some data into it......and i am reopening the file again but ......i get a error cannot open file....... $::file= "\adder\testfile.txt" open(TEST1,$::file); some write operation close(TEST1) open(TEST1,$::file) 'I GET A ERROR CAN OPEN... (2 Replies)
Discussion started by: vivekshankar
2 Replies

10. HP-UX

Inter Process File Handling Problem

Hi All, i am running a oracle procedure which writes a file . The same file is picked up by another script which runs in a cron after every 5 minutes. Now the problem is that sometimes my script picks up a file while the procedure is still writing data in the file. is there is any way i... (4 Replies)
Discussion started by: saurabhjain
4 Replies
Login or Register to Ask a Question