1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Write a program to copy a file to a destination file using message queues. ?

Discussion in 'C' started by krishnampkkm, Mar 3, 2010.

  1. krishnampkkm

    krishnampkkm New Member

    Joined:
    Jul 1, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin::cryin:
     
  2. ungalnanban

    ungalnanban New Member

    Joined:
    Feb 19, 2010
    Messages:
    45
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    Chennai
    Give me your code..
    What you tried for this?
     
  3. abubacker1

    abubacker1 New Member

    Joined:
    Feb 20, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Server process writes the chunk of the files into the message queue , why you
    need four process to read from the message queue.

    Confused ?
     
  4. karthigayan

    karthigayan New Member

    Joined:
    Feb 19, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    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 :

    msgget
    msgsnd
    msgctl
    msgrcv
    semget
    semop
     
  5. krishnampkkm

    krishnampkkm New Member

    Joined:
    Jul 1, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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

    Thanking u...........
    :p:p:p:p
     
  6. krishnampkkm

    krishnampkkm New Member

    Joined:
    Jul 1, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Yeeesss

    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 ?

    program1 :

    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)

    program2 :

    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....


    with regards
    KRISH:lipsrseal
     

Share This Page