ECET360 Lab 2
Process Simulation
Name: ______________________ Date: ___________
1. Objectives
• To learn how to use NetBean IDE to create, built and debug a C/C++ program.
• To learn how to apply fork(), getpid(), getppid(), pipe(), read() , write(), close() and exit().
• To gain understanding of inter-process communication.
2. Software Installation
In this lab, you will need to download two free (yet sophisticated) application programs: NetBean IDE 8.2 and Cygwin. During installation, please use correct .exe files depending on if your Windows is 32-bit or 64-bit.
Step 1. Install NetBean IDE 8.2 from:
https://netbeans.org/downloads/
Follow the instructions from:
https://netbeans.org/community/releases/80/cpp-setup-instructions.html#downloading
Pay careful attention to the instructions after the following line on the above website page:
To install the GNU gcc and g++ compilers, make, and gdb debugger from cygwin.com:
Step 2. Install cygwin, go to https://cygwin.com/. Keep consistency, use either 64-bit or 32-bit depending on your Windows.
Step 3. Watch the following YouTube video, so that you know how to add the path.
Try a simple project such as HelloWorld first.
When debugging the project (Debug -> Debug Project HelloWorld ), you may encounter the pop up window asking for additional paths. In this window, next to debug, add C:\cygwin64\bin\gdb.exe and next to make, add C:\cygwin64\bin\make.exe. This is to include all the necessary build and debug applications. Then, click on OK.
2. Procedures
1) Simulate Process Creation
a. Write a C/C++ program to create a child process. Your program should have the following components:
• Display a message to indicate the start of the program
• Make a system call fork() to create a child process
• Use if…else if…else (or switch…case) to determine if the process is created successfully or failed. If successful, print the parent or child process and its ID (getpid() for child process, getppid() for parent) accordingly; if failed, display a message to indicate that it failed.
• Before return 0 in the main, display a message to inform that the program has ended.
b. Built (use F11 or Run -> Build Project) and debug (Ctrl+F5 or Debug -> Debug Project) the program. Copy the source file below. (10 pts)
c. Run it for at least three times. Use Snipping Tool to crop each output and paste below. Explain the results. (10 pts)
2) Simulate Inter-process Communication
a. Write a C/C++ program to simulate the inter-process communication between a child process and a parent process. You need to modify the program you wrote in the procedure 1). In your program:
• First, use pipe() to generate a buffer. The pipe should return a status (int), which should be tested to see if it is successful. If not, print error message.
• Create a child process.
• If the process creation is successful, send a short message (a character string) from child process by using write() to the pipe. In the parent process, use read() to receive the string from the child.
• In each process, display a proper message to show the sending and receiving. A sample output could be:
• In both processes, take caution where to use close().
b. Built and debug the program. Copy the source file below. (20 pts)
c. Run the program and paste the output below. (5 pts)
d. Explain how your part 2) program works in five to eight sentences. (5 pts)
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.