Learning Goal: I’m working on a java multi-part question and need an explanation and answer to help me learn.
Purpose:To go over:Processes
fork() and execl()
Signals
Computing
Please ssh into cdmlsrvprd01.dpu.depaul.edu or use your own Unix machine.
Description
The mother of two children was going yardwork while wearing a decorative pin in her hair. Unfortunately, she lost her pin in a pile of grass. She wants to motivate her children to find the pin: $20 to whomever finds it first!
Sample output:
$ ./mother
Mother: “I will give $20 to whomever finds my decorative pin in the pile of grass. Go!”
Betty 8649: “Mom, have you thought of using a magnet?”
Fred 8650: “It smells nice, but no pin yet.”
Betty 8649: “Mom, have you thought of using a magnet?”
Fred 8650: “It smells nice, but no pin yet.”
Betty 8649: “Ouch! I got pricked by a . . . Hey, look at what I found!”
Mother: “Thank you for finding my pin, here is $20”
Fred 8650: “It smells nice, but no pin yet.”
Betty 8649: “Yay! I win! $20 is all mine!”
Fred 8650: “Mom, have you thought of using a magnet?”
Fred 8650: “Man! Now my hands are itchy.”
$ ./mother
Mother: “I will give $20 to whomever finds my decorative pin in the pile of grass. Go!”
Fred 8659: “Ouch! I got pricked by a . . . Hey, look at what I found!”
Betty 8658: “It’s just grass, not pin yet.”
Mother: “Thank you for finding my pin, here is $20”
Betty 8658: “It smells nice, but no pin yet.”
Betty 8658: “That wasn’t fair! I was just getting started!”
Fred 8659: “Yay! I win! $20 is all mine!”
$ ./mother
Mother: “I will give $20 to whomever finds my decorative pin in the pile of grass. Go!”
Catherine 8668: “Ouch! I got pricked by a . . . Hey, look at what I found!”
Gerald 8669: “It smells nice, but no pin yet.”
Mother: “Thank you for finding my pin, here is $20”
Catherine 8668: “Yay! I win! $20 is all mine!”
Gerald 8669: “Ouch! I got pricked by a . . . Hey, look at what I found!”
Gerald 8669: “Yay! I win! $20 is all mine!”
Mother: “Thank you for finding my pin, here is $20”
$ ./mother
Mother: “I will give $20 to whomever finds my decorative pin in the pile of grass. Go!”
Hal 8688: “Mom, have you thought of using a magnet?”
Dorothy 8687: “Mom, have you thought of using a magnet?”
Dorothy 8687: “It’s just grass, not pin yet.”
Hal 8688: “It smells nice, but no pin yet.”
Dorothy 8687: “It smells nice, but no pin yet.”
Hal 8688: “Ouch! I got pricked by a . . . Hey, look at what I found!”
Mother: “Thank you for finding my pin, here is $20”
Dorothy 8687: “It’s just grass, not pin yet.”
Dorothy 8687: “Man! Now my hands are itchy.”
Hal 8688: “Yay! I win! $20 is all mine!”
Protocol:
There are 2 programs (mother.c and child.c) that run 3 processes (1 mother, 2 children).
mother.c installs a SIGUSR1 signal handler, and fork()s and execl()s both child processes. She then hangs out.
The child processes installs a SIGTERM signal handler, and look for the pin.
When a child finds it, the child sends SIGUSR1 to its parent (the mother process).
When the mother receives SIGUSR1, it sends SIGTERM to all of its children, causing them to stop.
The mother then wait()s for both children, and quits herself.
Mother
|
|fork()/execl() child0
|—————->|
| |
|fork()/execl() | child1
|—————–|———–>|
| | |
| | |
| | |
| | |
| (searching) (searching)
| | |
| | |
| SIGUSR1 | |
|<----------------| | | | | | SIGTERM | | |---------------->| |
| | |
| SIGTERM | |
|—————–|———–>|
| | |
| (stops) (stops)
|
(stops)
Assignment:
mother.cStart with this code:#include
#include
#include
#include
#include
const char* FEMALE_NAME_ARRAY[]
= {“Anna”,
“Betty”,
“Catherine”,
“Dorothy”
};
const char* MALE_NAME_ARRAY[]
= {“Eric”,
“Fred”,
“Gerald”,
“Hal”
};
const int NUM_CHILDREN = 2;You may change the names, but please keep both arrays the same length!
main() should do the following:srand(getpid());
This resets the random number generator so that the program does not behave exactly the same each time.
Install a simple handler to be called when SIGUSR1 is received. What will it do? Keep reading!
printf(“Mother: “I will give $20 to whomever finds my “”

For This or a Similar Paper Click Here To Order Now