|
From: Jeroen N. W. <jn...@xs...> - 2005-08-26 18:46:58
|
> On Fri, 26 Aug 2005, Jeroen N. Witmond wrote: > >> Just for a lark, I ran the program in my previous post under >> valgrind/memcheck 3.1.SVN. Unfortunately, this shows a possible problem >> in >> valgrind: the output of the printf on line 16 is produced twice. The >> output of valgrind -v appears below. > > I think what Valgrind is doing is ok. Your printf() call doesn't end in a > newline and so the output doesn't have to be flushed to stdout > immediately. As a result, it's still sitting in the printf buffer when > the fork occurs. And then it subsequently gets flushed in the parent and > the child. > I am not sure I understand. The parent should flush the buffer, and does, as the text 'done.' is produced. The child is told to SIGQUIT (dump core and terminate), and should die immediatelly. When running outside of valgrind it does. Are you saying that the flushing of the child's buffer is an artifact introduced by valgrind? ;-) > If you add a newline to the printf() call, or call fflush(stdout) after > the printf() call, the string only gets printed once when run under > Valgrind. > Correct. Jeroen. |