Why does forking my process cause the file to be read infinitely

后端 未结 4 1298
小蘑菇
小蘑菇 2020-11-29 12:08

I\'ve boiled down my entire program to a short main that replicates the issue, so forgive me for it not making any sense.

input.txt is a text file that has a couple

4条回答
  •  独厮守ぢ
    2020-11-29 12:53

    As /u/visibleman pointed out, the child thread is closing the file and messing things up in main.

    I was able to work around it by checking if the program is in terminal mode with

    !isatty(fileno(stdin))
    

    And if stdin has been redirected, then it will read all of it into a linkedlist before doing any processing or forking.

提交回复
热议问题