Write a C program to create 3 child processes which read from 3 different files and write to the parent process using pipes. Each child should wait a random amount of time (3 -10 seconds) between writing each 50 characters. The father should read from pipes and write everything he gets (from all 3 files) into one new file.

Recommended Answers

All 2 Replies

And your question is?

Seems clear to me. Set up array of 3 files to read. Fork 3 child processes (see fork/exec man pages), each of which reads one of the files. Each sleeps for 3-10 seconds (random time I would assume), at which point they send 50 characters (are they 8-bit, or 16-bit chars?) to the parent process using a pipe. The parent/father process reads the pipes, and writes the data into the output file. Not a major problem. Your issues are to understand how fork/exec works, and how pipes work. Everything else is noise. The random sleep factor may be an issue, but learn about using random numbers to deal with this stuff - I have to do it all the time in my work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.