In: Computer Science
What’s the output of following code fragment:
#include<stdio.h>
#include<signal.h>
void response (int sig_no) { printf("25"); }
void response2 (int sig_no) { printf("43"); }
int main() {
int id = getpid();
signal(SIGUSR1, response);
signal(SIGKILL, response2);
for(int i=0; i<4; i++) {
sleep(1);
if (i % 3 == 0) { kill(id, SIGUSR1); }
else { kill(id, SIGKILL); }
}
return 0;
}
source code:
#include<stdio.h>
#include<signal.h>
void response (int sig_no) { printf("25"); }
void response2 (int sig_no) { printf("43"); }
int main() {
int id = getpid();
signal(SIGUSR1, response);
signal(SIGKILL, response2);
for(int i=0; i<4; i++) {
sleep(1);
if (i % 3 == 0) { kill(id, SIGUSR1); }
else { kill(id, SIGKILL); }
}
return 0;
}
output:
Killed
screenshot:
if the answer is helpful ,please provide a like