-
i need some advice
im making a school project in c programming.. and i need some advice.
the program is about an hospital.
i have made a struct which holds the information about the patiens infomation such as social sec. nr, injury ect.
there has to be 2 processors which reseive these patiens, and they can only take on at a time. The rest have to wait in the waiting room
my quastion is how can do that?
i was thinking about creating to processors by running fork(), 2 times. and the create a pipe transferring the whole struct. Is this possible and how do i tranfor a whole struct with a pipe?
my secound quastion is how should i make sure that only the 2 processors only reseive 1 patient at a time. I was thinking about a semifor.. which i could initialize to 2... how can i do that
pls help.. and keep it as simple as possible.. im new in the field.. thanks
-
> Is this possible and how do i tranfor a whole struct with a pipe?
Yes, you should be able to write() a block of binary data to the file and read() it again at the other end. But make sure the struct does not contain any pointers, because the pointer won't mean anything when it's read at the other end.
> my secound quastion is how should i make sure that only the 2 processors only reseive 1 patient at a time
You send a patient to one of the receiver tasks, and then wait for a "finished" message in response. If you have patients in the waiting room, then send another one.