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 12-05-2001, 03:30 AM   #1
oyoyoOnLinux
LQ Newbie
 
Registered: Dec 2001
Posts: 1

Rep: Reputation: 0
linux software interrupt


does anyone can tell me how can i do software interrupt in linux...
please help me
thanks
 
Old 12-05-2001, 04:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
would you not be better of using exceptions instead? much more controlled and easy to handle than interrupts, and i'm not sure you can actually do that even.
 
Old 12-05-2001, 06:18 PM   #3
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
interrupts are handled almost exclusively in the kernel - if you want a program to use them, you probably need to refer to the driver module for the hardware that you're programming for.
 
Old 12-05-2001, 06:23 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Exceptions can't be used in the place of signals. Signals are a form of interprocess communication where exceptions are not.

There are several different signals that can be caught. In this example the interrupt signal (control C) is caught.
The ignore is put in the handler so we don't get a signal while we are processing the signal. The rule of thumb is to keep the code in the handler as short as possible.

Code:
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>

static void
sig_int()
{
   /* Signal Interrupt, Captures Control-C  */
   
   if ((int)signal(SIGINT, SIG_IGN) == -1)   /* Ignore ^C  */
      perror("Signal Error");
      
   printf( "Control-C is caught\n\n>" );

   if ((int)signal(SIGINT, sig_int) == -1)
      perror("Signal Error");


   return;

}

main()
{
   char strIn[256];


//   if ((int)signal(SIGINT, SIG_IGN) == -1)   /* Ignore ^C  */
//      perror("Signal Error");

   if ((int)signal(SIGINT, sig_int) == -1)   /* catch ^C  */
      perror("Signal Error");

   while( 1 )
   {
      printf( "> " );
      gets( strIn );
      printf( "%s\n", strIn );
   }

}
 
  


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
Linux Interrupt Handler lucky6969b Linux - Software 1 12-01-2005 11:55 AM
interrupt hooking in linux fuzzyBuzz Programming 1 09-21-2005 06:20 PM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM
linux-2.6.6 hdc: lost interrupt Andrew Benton LinuxQuestions.org Member Success Stories 7 11-15-2004 09:29 AM
how to set an interrupt (irq) via software cardias Programming 2 09-20-2004 07:37 PM

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

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