Question: Problem 1. Continuing with signals and using as a base your previous program (with fork()), write another using a signal from one of the processes
Problem 1.
Continuing with signals and using as a base your previous program (with fork()), write another using a signal from one of the processes to stop the other process, then the stopped process has to be resumed with another (different) signal; do not use SIGALRM for these. Use the command kill -l to display the signals available, and man 7 signal to see the manual.
Write a program to display the first 10 fibonacci numbers, with a delay of one second between them. The program writing the numbers must be stopped at the middle of the running, and the process stopping it must write a message about the event and after a few seconds the program must be resumed writing the following five fibonacci numbers and finishing with a message.
Problem 2.
Write a second program that will behave similar as the previous one but this time without the use of the fork(). This means an autonomous program that will stop and resume itself using signals, other that SIGALRM for these.
--------------------------
I'm pretty sure I figured out part 1, heree is my code:
----------------------------
#include
#include
#include
#include
#include
int main(){
int i, next, t1=0, t2= 1;
printf("Fib series ");
pid_t cpid, pid = fork();
switch (pid){
case -1:
printf("Error, child process failed ");
break;
case 0:
cpid = getpid();
for(i=0; i <= 10; i++){
if(i==0){
printf("%d ", t1);
sleep(1);
continue;
}
if(i==1){
printf("%d ", t2);
sleep(1);
continue;
}
if(i==5){
kill(cpid,19);
sleep(5);
printf("Program is being halted... ");
}
if(i != 5){
next = t1 + t2;
t1 = t2;
t2 = next;
printf("%d ", next);
sleep(1);
}
}
default:
sleep(6);
kill(pid, SIGCONT);
sleep(10);
break;
}
--------------------------------
Just need help with part 2. Please explain it in in simple terms, I'm not that good at coding. Thanks!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
