Question
Linux & C code help with creating a child process and kills itself with SIGNAL. I provided most of the code, I need some help
Linux & C code help with creating a child process and kills itself with SIGNAL. I provided most of the code, I need some help to finish. Please provide output screen shot as well. Thank you!
A Process creates a child process. Child process will print out "hello 0" "hello 1" ..... 1 line per second. After a certain number of seconds(user input), it kills itself WITH signal mechanism ONLY, don't use exit() on the child. You can use alarm() which may show the "Alarm clock". (Alarm clock may not appear depending on your environment. It is not required). Your output should look like....
hello 0
hello 1
hello 2
hello 3
hello 4
[... etc .]
Alarm clock [may or may not appear]
Here is my code......
Use alarm to kill the process.
Hello world printed out every second for 5 seconds, then terminate.
MUST use system call alarm, not EXIT.
#include
Unsigned int alarm
Sleep ()m
Takes 1 input. Make calling process wait seconds
#include
Main (..){
Int n;
N = user input; // user input = convert string 5 to # 5
(How long hello will be printed out)
Int pid;
If ((pid = fork() < 0){ // error)
Else if (pid > 0){
//parent process
Only child prints hello, parent process does nothing
Wait();
Printf(this is parent so wait );
}
Else if (pid == 0){ //this is child
// print hello time or n times
//once per second
//kill process after n seconds
// must use alarm
Int count = 0;
Alarm(?); // give alarm a #
//alarm doesnt ring, then print out while loop
While (1){
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started