The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 4 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Can someone help me with my homework? It's due Sunday at 11pm
WBIT 3500 Architecture and Operating System
Â
Assignment 8
Multi-Process and Multi-Thread Programming
Â
Â
Fork a Process
The following code can fork a child process. Both parent and child process can all print out 50 lines. Please modify the code to make parent process print out the even number of lines among the 50 lines, and the child process will only print out the odd number of lines. In your output message, please specify if the process is a parent process or a child process. And also output the process id.Please submit your source code, and the screenshot of the running result.
Â
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
Â
#define  MAX_COUNT 50
#define  BUF_SIZE  100
Â
void main(void)
{
pid_tpid;
inti;
charbuf[BUF_SIZE];
Â
fork();
pid = getpid();
for (i = 1; i<= MAX_COUNT; i++) {
sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
write(1, buf, strlen(buf));
    }
}
Â
Submission:
1.     Please submit your C language source code;
2.     Please submit at least two snapshots to show your compiling and running results under Cygwin.
Â
Grading Rubric
|
Criteria |
Points |
|
|
Source code without compiling error |
30 |
|
|
Screenshotsclearly show all the required information |
20 |
|
|
 Testing: |
Even number output for parent process |
10 |
|
Odd number output for child process |
10 |
|
|
Specify parent process with correct Process ID |
15 |
|
|
Specify child process with correct Process ID |
15 |
|
Â
Â
Â
Â
Â
Â
Â
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly