I'm new to this system programming bit. I have no idea how to do this stuff, so keep this in mind. I have never forked/execed a process, used semaphores for synchronization, or used shared memory for synchronication, with my code. Ever.
I have an input file in the following format:
There are up to 5 lines in the file. Reading input from the file is not a problem. Based on the number of lines in the file, I am to get, from the user, a permutation of numbers. This is also not a problem: if the user enters 2 1 3 4, I am all set. The problem is, I have to fork (in this example) 4 processes and synchronize them using semaphores. So, if the user enters 2 1 3 4, here's what I have to output:Code:Message 1 Message 2 Message 3 Message 4
It outputs the messages from the file, followed by the child's number, followed by the child's PID. Seems simple, right? All's I need to do is read the file into a local variable (already done), fork x children (where x = number of lines in the file), execute them according to the order the user requests, terminate the processes, and be finished.Code:Message 2: Forked child number 2, PID 39127 Message 1: Forked child number 1, PID 39657 Message 3: Forked child number 3, PID 39534 Message 4: Forked child number 4, PID 39178
Please help me out here, I've never done this stuff before
Thanks in advance