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
#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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started