Difference between synchronous and asynchronous interrupt ?

+4 votes

6,153 views

I am getting confused between trap and interrupt. As trap is software driven and interrupt is hardware originated. Every instruction of a program get executed in CPU then how trap and interrupt differs ? A detailed example can help out me. Thanks in advance.

2 Answers

+1 vote

Interrupt is a very generic term. There are two types of interrupt occurs in system, one through software and another one through hardware. Suppose a programer has written such a statement in his/her program which causes interrupt in the system i.e called synchronous interrupt or software interrupt like division by 0. Another class of interrupt is generated in system due to hardware like I/O interrupt, Hard disk. Hardware interrupt comes under class of "asynchronous interrupt" like you pressed Ctrl-C.

1.Synchronous Interrupts (also know on as software interrupts)
- Synchronous Interrupts are generated by CPU's control unit on facing some abnormal condition; these are also know as exception in Intel's terminology. These are interrupts which are generated by CPU itself either when CPU detects an abnormal condition or CPU executes some of the special instructions like 'int' or 'int3' etc.
2.Asynchronous Interrupts (also know as hardware interrupts)
- On other hand, Asynchronous Interrupts are those, which actually are generated by outside world (devices connected to CPU), As these interrupts can occur at any point of time, these are known as Asynchronous interrupts.

I am maintaining a program in Python 2 and need to send it a Keyboard Interrupt to close it. Unfortunately, the program is used as a subprocess in a wrapper subprocess, and so I cannot just directly press CTL-C; I have to use a signal.
When I run the program "bare" (not in a subprocess), I have found that raising a SIGINT (kill -2) raises a Keyboard Interrupt in the program. But when I run the program in the wrapper process, kill -2 no longer has any effect (whether it is raised by the wrapper or externally).
Why is that the case? Does Pythons interpretation of SIGINT as a Keyboard Interrupt only obtain when the program is run in a terminal? Is there something else Im missing?