Saturday, May 15, 2010

Source Code Program To Demonstrate Four signal Interrupt Linux Shell Programming

To create any four signal and interrupt.
By through simple action it will create Signal. For signal implementation we insert signal.h header file. it has 3 function window_changed(), quit(),kills(),catch_child(init sig_num).
Linux shell Programming Source code in C | signal interrupt
#include<stdio.h>
#include<signal.h>
void window_changed()
{
printf("\n\tWindow size is changed\n\n");
}
void quit()
{
printf("\n\tCtrll backslash pressed\n");
}
void kills()
{
printf("\n\tcontrol Z is pressed to stop the process\n");
exit(0);
}
void catch_child(int sig_num)
{
printf("\n\tchild exited\n");
}
void arm()
{
int pid,i;
int status;
signal(SIGCHLD,catch_child);
printf("\n\talarm is ringing\n");
pid=fork();
switch(pid)
{
case 0: printf("\nchild is created\n");
for(i=0;i<4;i++)
{
printf("\nchild count %d",i);
sleep(1);
}
exit(1);
break;
default: wait(&status);
kill(pid,SIGKILL);
}
}
int main()
{
int pid;
printf("\n\tEnter a key");
signal(SIGWINCH,window_changed);
signal(SIGQUIT,quit);
signal(SIGALRM,arm);
signal(SIGTSTP,kills);
alarm(5);
for(;;)
{
}
return 0;
}
FOUR SIGNAL AND INTERRUPT OUTPUT:
Enter a key
alarm is ringing
child is created
child count 0
child count 1
child count 2
child count 3
child exited
^\
Ctrll backslash pressed
Window size is changed
^Z
control Z is pressed to stop the process
CONCLUSION:  The following c program demonstrate signals and interrupt.

0 comments:

Flag counter

free counters