LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-19-2005, 07:46 AM   #1
chimpu
LQ Newbie
 
Registered: Sep 2005
Posts: 1

Rep: Reputation: 0
Question handling ctrl D and signals


Can we capture ctrl D if yes how if no why not...

already we know it generated EOF but how to write a handler for it
 
Old 09-19-2005, 08:43 AM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
If you're trying to capture signals, you use the signal() call.

First, you write a signal handler:

void handler(int signal)
{
printf("Signal trapped: %d\n", signal);
return;
}

Then you call signal, for whatever signal this will be handling:

signal(<signal number>, handler);

As an example:

Code:
#include <stdio.h>
#include <signal.h>

void handler(int sig)
{
    printf("Signal trapped: %d\n", sig);
    exit(0);
    return;
}

int main()
{
    signal(1, handler);
    signal(2, handler);
    signal(3, handler);
    signal(6, handler);
    signal(9, handler);
    signal(13, handler);
    signal(15, handler);
    signal(19, handler);

    while (1);
}
If you run that, and press CTRL+C it will show you what signal is being sent.
See bits/signum.h for a list of signals.
 
  


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
ctrl+c & ctrl+v equivalent for Gnome terminal window? halfpower Linux - General 2 11-29-2005 02:57 AM
!!! about signals !!! b2na Programming 4 02-04-2005 12:34 AM
dark screen when pressing Ctrl + Alt + Backspace or Ctrl + Alt F1-F6 in Gnome or KDE trinoo Slackware 5 01-28-2005 08:13 AM
no ctrl-a or ctrl-z in emacs or on command line? ashlock Fedora 5 12-30-2003 08:00 PM
ctrl+ c ctrl +v not working in windows xp Astro General 3 10-20-2003 08:42 PM

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

All times are GMT -5. The time now is 09:18 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