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:
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.
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 :confused:
Thanks in advance
Oh come on, I'm sure someone knows what's going on. You have answers to every other question except mine.
All I need to do is fork 4 processes, have each one wait for a semaphore, and have them execute in a specific order based on which semaphore was signalled.
> You have answers to every other question except mine.
Has info / examples of fork and IPC