Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

b) Write a C/C++-program that creates a fan of 10 processes. That is, process 1

ID: 3819542 • Letter: B

Question

b) Write a C/C++-program that creates a fan of 10 processes. That is, process 1 is the parent of prcocesses 2, 3, 4, 5, 6 and so on. a) Write a simple program named test1.cpp, which contains an infinite while loop. Compile the program to an executable named test1 and run it in the background. b) Write a shell script that searches for whether the process test1 is in the system. If it is not, your script displays the message 'Process test1 not running!'. If it is running, your script kills the process, and displays the message 'Process test1 killed!'. Turn in your programs along with your outputs.

Explanation / Answer

Below is the executable code :

test1.cpp

#include <iostream>

using namespace std;

int main () {

for( ; ; ) { cout << "This is the infinite loop." << endl; }

return 0;

}

Convert the above cpp code to executable (.exe) file using Visual c++ or Turbo c++

Run the executable file.

Now , Shell Script

#!/bin/bash

echo " Enter the process name:"
read $proc_name
if pgrep $proc_name
then
echo " $proc_name running "
pkill $proc_name
echo "$proc_name got killed"
else
echo " $proc_name is not

running/stopped "
fi

Run the shell script and stop the process test1.