LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-16-2006, 02:14 PM   #1
mohsin-mm
Member
 
Registered: Sep 2005
Posts: 45

Rep: Reputation: 15
Question signal hangler problem


hello guyz plz help me in sorting our these problems of this script plz chek this is correct i m getting errors while compiling .. these are the errors

==========================================
sig2.c: In function `main':
sig2.c:10: `SIGINT' undeclared (first use in this function)
sig2.c:10: (Each undeclared identifier is reported only once
sig2.c:10: for each function it appears in.)
sig2.c:11: `SIGQUIT' undeclared (first use in this function)
sig2.c: In function `sigproc':
sig2.c:16: `SIGINT' undeclared (first use in this function)
==============================================
file
=================================================
[mohsin@localhost signals]$ vi sig2.c

#include <stdio.h>

void sigproc(void);

void quitproc(void);

main()
{
signal(SIGINT, sigproc);
signal(SIGQUIT, quitproc);
printf("ctrl-c disabled use ctrl-\\ to quit \n");
for(;; /* infinite loop */}

void sigproc()
{ signal(SIGINT, sigproc); /* */
/* NOTE some versions of UNIX will reset signal to default
after each call. So for portability reset signal each time */

printf("you have pressed ctrl-c \n");
}
==================================
also i m searhing any examples for practicing basic signals in linux if any one of you find plz share ... in this forum
thnx alot
 
Old 02-16-2006, 02:15 PM   #2
mohsin-mm
Member
 
Registered: Sep 2005
Posts: 45

Original Poster
Rep: Reputation: 15
the simely in the for loop is due to textshortcut i hope you all know plz reply thnx
 
Old 02-16-2006, 04:28 PM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
#include <signal.h> ??
 
Old 02-17-2006, 10:31 AM   #4
mohsin-mm
Member
 
Registered: Sep 2005
Posts: 45

Original Poster
Rep: Reputation: 15
thnx for replying dear now i get these errors after including signal.h
===========
sig2.c:11: warning: passing arg 2 of `signal' from incompatible pointer type
sig2.c:12: warning: passing arg 2 of `signal' from incompatible pointer type
sig2.c: In function `sigproc':
sig2.c:17: warning: passing arg 2 of `signal' from incompatible pointer type
 
Old 02-17-2006, 10:32 AM   #5
mohsin-mm
Member
 
Registered: Sep 2005
Posts: 45

Original Poster
Rep: Reputation: 15
if any other link to basic signal handling link plz tell me thnx
 
Old 02-17-2006, 10:58 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
The following C code should work.
Code:
#include <stdio.h>     /* standard I/O functions                         */
#include <unistd.h>    /* standard unix functions, like getpid()         */
#include <signal.h>    /* signal name macros, and the signal() prototype */

/* first, here is the signal handler */
void catch_int(int sig_num)
{
    /* re-set the signal handler again to catch_int, for next time */
    signal(SIGINT, catch_int);
    printf("Don't do that\n");
    fflush(stdout);
}

int main(int argc, char* argv[])
{
    /* set the INT (Ctrl-C) signal handler to 'catch_int' */
    signal(SIGINT, catch_int);
    /* now, lets get into an infinite loop of doing nothing. */
    for ( ;; )
        pause();
}
Taken from Introduction to Unix Signals Programming
 
Old 02-18-2006, 01:11 AM   #7
mohsin-mm
Member
 
Registered: Sep 2005
Posts: 45

Original Poster
Rep: Reputation: 15
thnx dear ... but could you tell me that what this function do coz i m not on root acount so might it do anything wrong ... i dotn think so
 
Old 02-18-2006, 01:13 AM   #8
mohsin-mm
Member
 
Registered: Sep 2005
Posts: 45

Original Poster
Rep: Reputation: 15
thnx finally your code helped me good work , plz tell me the code
signal(SIGINT, catch_int);
howz it handle the ctrl + c signal ... or its default handler

signal() functions
kz what to do if i use this code to handle do same but for "ct+z"

also sig_ign is used to ignore a signal i think does that work

thnx

Last edited by mohsin-mm; 02-18-2006 at 01:23 AM.
 
Old 02-18-2006, 05:55 PM   #9
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Ctrl + C is SIGINT the interupt signal
Ctrl + Z is SIGTSTP the suspend signal
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
squid stops due to signal 6 and signal 25 simplyrahul Linux - Software 3 05-28-2011 01:05 AM
pthread signal problem again xinwang00 Programming 4 11-18-2003 02:21 PM
Signal 6: Unknown Signal <=> Error with MAYA4.X under Linux SOLVED!!!! Faeroon Linux - Software 9 05-09-2003 01:57 PM
Signal: 6 (Unknown Signal) - Problems running a program Faeroon Linux - Software 86 01-14-2003 12:08 AM
'c' unix signal problem GAFling Programming 1 01-08-2002 01:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration