COMP2560 Lab #7 –ps, kill, and signals Solved

35.00 $

Category:

Description

Rate this product

Use shell terminal to launch a GUI-based application to be executed in the background. Here are examples to start image viewer gimp on CS server:

>>>>> gimp &

>>>>> gimp imagefile.ppm &

Use command kill -9 pid to terminate this application.

Part II

Repeat the above. This time, do not use the ampersand. The application is executed in fore ground. Open another terminal. Use command ps to find out the process id of the application that you have launched, and then use command kill -9 pid to terminate it.

Part III

Write a C program where two child processes are created using fork(). The parent process and child processes all write into a shared file using system call write(). The file name is given from command line.

Define three strings like this:

buf[0] = “EXAM! EXAM! EXAM!\n”;

buf[1] = “HELP! HELP! HELP!\n”;

buf[2] = “STUDY! STUDY! STUDY!\n”;

 

The parent process will open the file using open() before the fork. The first child will write the content of buf[0] into the file. Then the second child will write the content of buf[1] into the file. Finally, the parent will write the content of buf[2] into the file and close the file. Add sleep(5) after each write() statement.

 

Use signal to coordinate the access to the shared file, so that the file is accessed with mutual exclusion.

 

In addition to writing to the file, both parent and child processes should also write some related information to the terminal according to what the sample shows.

Sample run:

 

  • lab7-wy6afr.zip