Perl multi-process

Koelling

I Think Different
Hello all,

I'm trying to write a program, actually a pair of programs in perl. The first program should accept a commandline argument and write it to a file. The second program should loop over the lines in that file and process each one in turn, then delete it. It's your typical queue setup.

I'm trying to figure out how I can remove the entry from the file once it's been processed. I don't want to miss any commands from the enqueue program so I need to have a lock on the file. When I open the file as read/write (+<) on the deque program, I can't delete the first line since it seems to append to the file. What I'd like to do is open the file as read only (or readwrite, doesn't matter), process the line and save the remainder of the file to an array, then open it again for writing since that will clear the whole file and write out the array. The only problem with this is closing the file will release the lock and my enque program could write to the file!

I know there's some smart people here, I hope you will find my problem entertaining (or else you have already seen the answer.) Thanks everyone! Alternate solutions welcomed as well.
 
Sounds like what you want is a "named pipe". Do a little google research. They're kind of like a combination between a file and a piped queue.
 
hmm interesting, does this work just to write to a file? In theory, it'd be cool if I could use the enqueue program independent of the dequeue so I could if I wanted to just use the enqueue program to queue up the commands and run the deque loop later.

What I'm using it for is sometimes I have a lot of things I want to install using fink but I don't want to install them right then or fink is already running and I don't want to start more than one build process. This way I can "enqueue fink install perl" and it will install it once the current program finishes building or the next time I run dequeue.

Thanks for the input, I'll take a look at named pipes. My experience with the shell pipe (|) seems to make it seem like you need both ends at once.
 
Well, with named pipes, you stuff a special "file" into a directory (mkfifo? I think that's the command). After that, you can read and write to it like a file, but with the functionality of an anonymous pipe on the command line. I'm not sure if contents are preserved between reboots, or if it's just stored in RAM, though, so do a little research on that.
 
Back
Top