Question: Ok running a c program on cmd and using tdm-gcc. The code i'm using says that fork can't be used, i think can someone help

Ok running a c program on cmd and using tdm-gcc. The code i'm using says that fork can't be used, i think can someone help me get this to run: Thanks

#include #include #include

#define MAX_COUNT 50 #define BUF_SIZE 100

void ChildProcess(void); /* child process prototype */ void ParentProcess(void); /* parent process prototype */

void main(void) { char buf[BUF_SIZE]; pid_t pid; pid=fork(); if(pid==0) ChildProcess(); else ParentProcess(); }

void ChildProcess(void) { int i; for(i=1;i<= MAX_COUNT;i++) { if(i%2!=0) //Checking condtion for and odd number of lines { sprintf(buf, "Child process: pid %d, value = %d ", pid, i); write(1, buf, strlen(buf)); } } }

void ParentProcess(void) { int i; for(i=1;i<=MAX_COUNT;i++) { if(i%2==0) //Checking condtion for even number of lines { sprintf(buf, "Parent process: pid %d, value = %d ", pid, i); write(1, buf, strlen(buf)); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!