Write a program to copy a file to a destination file using message queues.
The server (writer process) has to split the data in the file appropriately
and send it to the message queue. There should be one writer process which
writes into the message queue and four reader processes which read the
appropriate message from message queue and writes into the destination file.
Use semaphores to synchronize writing into the file by the reader process.
: cryin::c ryin::cr yin:
Write a program to copy a file to a destination file using message queues. ?
Give me your code..
What you tried for this?
Server process writes the chunk of the files into the message queue , why you
need four process to read from the message queue.
karthigayan like this
Here is the algorithm ,
1 . Create a message queue id by using the "msgget".
2 . Then open the source file and copy a line to the message queue buffer then send that to the queue.
3 . Among the four process any one has to lock the file by using the semophore functions.
4. And then the process has the read the queue.And it has to write the current contents of the message queue.
5.After some times it has to release the lock and increment the semaphore value to 1.
6. Using the loop just read every line and the same operations.
First Understand the functions :
Thanks for the information...Actually there is no need to use 4 reader processes, It is a class assignment question, so that I've to follow the question pattern
I've implemented a message queue,
here I used two programs one for server that writes
the source file to message queue. And with other program
I read the message queue and writes into destination file.
so one section is over ....
Now as per the question , there must be 4 reader process.
And have to provide synchronization. Four reader process means what...??
Four reader processes concurrently reads message from
queue and writes into one destination file. Am I correct.?
So in which mode have to open the destination file .,,,Append mode ?
1. open source file (read only)
2. create message queue.( msgget)
3. read file small block by block upto end of file.
4. writes into message queue and sends (msgsnd)
1. open dest file (write mode)
2. Get existing message queue.( msgget)
3. Receives messages (msgrcv)
4. writes into message.text to dest file.
So this is my current status of programs.... Now I use only two processes. And I wanna change it with one process write in to queue and 4 processes reading from queue. In the above algorithm where should add semaphores..... have to make a concept critical section here.....
Any suggestions or helps....