Skip to content

Commit

Permalink
Create testSig.c
Browse files Browse the repository at this point in the history
to see how to send signal from one process to another
  • Loading branch information
ashoksharma842 authored Dec 8, 2023
1 parent c10e48b commit 0e2e84f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions testSig.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

void sigint()
{
signal(SIGINT, sigint);
printf("sigint received\n");
}
void main ()
{
int pid;
pid = fork();
// printf("pid = %d:", pid);
if (!pid) {
printf("child pid = %d(%d)\n", getpid(), pid);
signal(SIGINT, sigint);
while(1);
} else {
printf("parent pid = %d\n", getpid());
printf("sending SIGINT\n");
kill(pid, SIGINT);
}
}

0 comments on commit 0e2e84f

Please sign in to comment.