0% found this document useful (0 votes)
3 views1 page

C Programs for Signal Handling in C

The document contains two C program examples that utilize signal function calls. The first program sends a message when CTRL C is pressed, while the second program ignores the CTRL C signal entirely. Both programs run indefinitely, demonstrating different signal handling behaviors in C.

Uploaded by

darshansrathod12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

C Programs for Signal Handling in C

The document contains two C program examples that utilize signal function calls. The first program sends a message when CTRL C is pressed, while the second program ignores the CTRL C signal entirely. Both programs run indefinitely, demonstrating different signal handling behaviors in C.

Uploaded by

darshansrathod12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

2.

1
Write a C program using signal function calls as follows: when CTRL C is pressed a
Signal, with message, “Press CTRL Z to terminate” should be sent.
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void my_handler(int signal)
{
printf("Problem encountered %d \n", signal);
}

int main()
{
(void) signal (SIGINT,my handler);

while(1)
{
printf("press contrl z to terminate \n");
sleep(2);
}
}

2.2
Write a C program using signal function calls as follows: when CTRL C is pressed
the signal should be ignored
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
(void) signal (SIGINT,SIG_IGN);
while(1)
{
printf("%d \n", getpid());

sleep(1);

}
}

You might also like