Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m writing a program that collects network data. I need to store one bit of in

ID: 652822 • Letter: I

Question

I'm writing a program that collects network data. I need to store one bit of information, a simple yes/no, somewhere so another process may read it. I have several options: writing a 1 or 0 to a file, touching / rming a file, writing a field into a database table, etc. There may be other ways that I am not aware of. What is the most elegant solution in this case? This program stores no other data, it only puts out an alert under certain conditions. Performance or ease of coding is no issue. Bonus points if your solution still works if I change my mind and make it two bits.

Explanation / Answer

Inter process communication isn't a small question. There is a lot of "it depends" in there. Perl has a whole chapter on the subject under perlipc

However for your scenario as described - I'd write a state file, flock it and then write your data there.

The flock ensures you don't have a race condition, and the file can be of arbitrary length. You can use filesystem permissions to grant access as is suitable for your needs.