Question

In: Computer Science

Linux Create two subprocesses using the system call fork(), and then use the system call signal()...

Linux Create two subprocesses using the system call fork(), and then use the system call signal() to let the parent process capture the interrupt signal on the keyboard (i.e., press the DEL key); The subprocess terminates after the subprocess captures the signal and outputs the following information separately: ​ “Child Process l is Killed by Parent!” ​ “Child Process 2 is Killed by Parent!” After the two child processes terminate, the parent process output the following information and terminate itself: ​ “Parent Process is Killed!” Program with screen shot and explanation. Thank you

Solutions

Expert Solution

#include <unistd.h>
#include <stdio.h>
#include <signal.h>

void sigint()    // signal Handler
{
    signal(SIGINT, sigint); /* reset signal */
    printf("CHILD: I have received a SIGINT %d \n", getpid());
}

int main()
{
    pid_t child_a, child_b;

    child_a = fork();

    if (child_a == 0) {      
        /* Child A code */

        printf("First Child %d \n", getpid());
        signal(SIGINT, sigint);   // Register signal
        pause();   // Wait for signal

    } else {
        child_b = fork();

        if (child_b == 0) {
            /* Child B code */

            printf("Second Child %d \n", getpid());
            signal(SIGINT, sigint); // Register signal
            pause(); // wait for signal

        } else {
            /* Parent Code */
            sleep(5);    // Lets child run first

            printf("Parent Start %d \n", getpid());

            kill(child_a, SIGINT);   // send signal to first child
            kill(child_b, SIGINT);   // send signal to second child
            wait(NULL); // wait for all child termination

            printf("Parent END %d \n", getpid());
        }
    }
    return 0;
}

******************* OUTPUT *****************

First Child 23827
Second Child 23828
Parent Start 23826
CHILD: I have received a SIGINT 23827
CHILD: I have received a SIGINT 23828
Fisrt child start after Pause
Second child start after Pause
Parent END 23826


Related Solutions

11. A fork() function call is a system call. true or false 12. A fork() function...
11. A fork() function call is a system call. true or false 12. A fork() function call in a user program is executed in user mode, not in kernel mode. true or false 13. Alice writes a high-level program using some programming language on her home desktop computer and using compilation it transforms into an executable file. Bob's home desktop computer will not execute Alice's executable file. What language was Alice's program written with? 14. Alice rewrites her high-level program...
The following program calls the fork() system call to create a child process. Suppose that the...
The following program calls the fork() system call to create a child process. Suppose that the actual pids of the parent process and child process are as follows: Parent process: 801 Child process:   802 (as returned by fork) Assume all supporting libraries have been included. => Use the answer text field to write the values of the pids printed at lines 1, 2, 3, and 4 (indicate each line number and the value printed). int main() {      pid_t pid,...
The following program calls the fork() system call to create a child process. Suppose that the...
The following program calls the fork() system call to create a child process. Suppose that the actual pids of the parent process and child process are as follows: Parent process: 801 Child process:   802 (as returned by fork) Assume all supporting libraries have been included. => Use the answer text field to write the values of the pids printed at lines 1, 2, 3, and 4 (indicate each line number and the value printed). int main() {      pid_t pid,...
Use fork() Create a program that reads characters from an input file. Use fork to create...
Use fork() Create a program that reads characters from an input file. Use fork to create parent and child processes. The parent process reads the input file. The input file only has letters, numbers. The parent process calculates and prints the frequency of the symbols in the message, creates the child processes, then prints the information once the child processes complete their execution. The child processes receives the information from the parent, generates the code of the assigned symbol by...
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
In Kali Linux, create two users Guest2 and Guest3. Use the user (for yourself in Question...
In Kali Linux, create two users Guest2 and Guest3. Use the user (for yourself in Question 1) to create a directory Ex-dir containing a text file File1.txt. I. Display the owner and group for the directory Ex-dir; (Take a screenshot of the command and its output) II. Change the group of the directory Ex-dir to Guest2; (Take a screenshot of the command) III. Change the permission mode of Ex-dir such that Guest 2 (as a group user) has permissions read...
Lab – Linux Fundamentals Instructions: Using Kali Linux, the Windows Linux Sub-System, or another Debian based...
Lab – Linux Fundamentals Instructions: Using Kali Linux, the Windows Linux Sub-System, or another Debian based Linux distribution, perform the following tasks based on the Linux Fundamentals lecture. For this lab, take screenshots for all major steps completed to illustrate that each task was successfully completed (the same method as would be used for other labs). 9. Display your current directory in the terminal 10. Display your current directories contents including the inode value and permissions for each file and...
Create an object call Accounts using python for a banking system. Initialize the account with three...
Create an object call Accounts using python for a banking system. Initialize the account with three data as inputs : Firstname, Lastname and initial deposit. Create 4 additional member functions: Deposit, Withdraw, Fee Calculations, interest The fee calculation is going to be $14 per month if the total amount in the account is less than $1000. Interest is set to be at 5%.
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O,...
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED a) open an existing text file passed to your program as a command-line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT