azaria has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I would like to consult with you : i need to manage one centeral file which is dynamically updated. this file is controling a queue under unix system. each time a user invoke a command "run", the file is been updated with the user name. if the user is in the top of the file then it will run any other second command (e.g: open a gui) and then he will be deleted from this list. in case he is not in the top of the file then he will wait in a loop until the other users from the list will complete their sessions. The problem of updating file (open(FILE,">>$file) and close(FILE)) that the file might be occupied for other user/s and their process will fail. I don't know how to use SIGNALs or to work with socket. Can you please help and send me examples, how can i do it in the simple way ? Thanks !!!!

Replies are listed 'Best First'.
Re: manage file in parallel
by jesuashok (Curate) on Jun 06, 2006 at 08:06 UTC
    Hi

    In this scenario, I would suggest you to use pipe. Pseudo code :-

    run has to read the named pipe whether any user name there or not. If user is there Give prefrences to the user write the second user name in the pipe, so that next time when run reads the pipe this will get the new username If no user run has to write the username in named pipe.

    "Keep pouring your ideas"
      First thanks for your fast reply. do you mean i need to use the $| =1 ? what if in the minute a user will open the file to write his name another user will try to write his name in the same , the action will fail, isn't ?
      A reply falls below the community's threshold of quality. You may see it by logging in.