Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

How does a period cost differ from a product cost?

Answered: 1 week ago