-1

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.

3
Contributors
2
Replies
33
Views
3 Years
Discussion Span
Last Post by rubberman
0

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.

Edited by rubberman

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.