I have a program which querys a romote database and distribute results thrugh email to users. I have been using it for quite a while. Recently it stopped working. When I ran it under shell I got broken pipe error after it has run about 2 min, but if I run it as root, it can run much longer (20 min) but still got broken pipe. I wonder what are causes of broken pipe?
I know that you can set up a time limit for user's process, if a process runs longer than the limit, it will get killed. Is the broken pipe the case?
In your particular case you seem to have some kind of race condition. See what processes are involved in the race (which one "wins" the race and should have waited for the other one) through pstree or something. Then find a way to delay the winner or make it play nice with the other.
A race condition is something else... It's when a non-atomic set of actions can be intercepted to affect the behaviour of the application. For instance, if I check for the existence of a file, and then create it if it doesn't exist, the time between the stat and the open is the race condition.
A broken pipe is like you said, except that it's specifically the input side of the pipe going away. ie, if you pump a bunch of data through more, and kill off more halfway through, the output side loses the file descriptor and gets killed with SIGPIPE.
How do you set up the time limit for which a user can run a process? I want to check that if it's the problem.
My program basically do two things, searching remote database and retrieving the results; sending results by email. Which process could be broken? The strange thing is the time before the pipe is broken is different for a user and a root user, with the latter being able to run the program much longer.