简体   繁体   中英

pipe causing processes to freeze

The program report launches two accessed processes. Report basically feeds accessed a list of filenames and accessed prints if they have been accessed in x days.

However, my implementation is causing accessed to freeze somehow. After running reports , nothing gets printed. When I run ps , I can see two accessed programs hanging around, not dying.

At first, I thought the method of reading from stdin was wrong in accessed , but I manually piped some filenames to it cat filenames.txt | ./accessed cat filenames.txt | ./accessed , and it works. So report program must be wrong.

I attached gdb to the frozen accessed processes and it seems that it is frozen at the while loop getline . So I changed the while loop to a single getline statement and it suddenly works. However, I need to read stdin until EOF. Any help on the possible sources of errors is very much appreciated. This is causing me much headache.

Schematics:

--------
|      |--------> Access1  ---> print stuff out
|report|
|______|--------> Access2 ----> print stuff out

Each process closes its own input pipe (after dup2'ing the read end).

However, they leave the other process's input pipe open. Each one will never see an EOF, even after the parent process closes it, since there's the possibility that the other child process might decide to send data to it.

The children should close each others' pipes (or be started without inheriting the other process's pipes).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM