mitnk / cicada

An old-school bash-like Unix shell written in Rust
https://hugo.wang/cicada/
MIT License
981 stars 50 forks source link

Pipeline Stuck when its Latter Commands Finished First #26

Closed mitnk closed 3 years ago

mitnk commented 4 years ago

cicada still has a bad issue that it stuck when the latter commands finish first. For example,

$ ps ax | head -n 3

If your system run a lot of programs, this pipeline will stuck, though you can hit CTRL+C to escape. Note: ps ax | tail does not suck.

USER       PID  PPID  PGID TPGID STAT COMMAND
mitnk     9471  9470  9470  9582 S    -cicada
root      9582  9471  9582  9582 S+   ps ax
mitnk     9583  9471  9582  9582 Z+   (head)

If the above command didn't stuck on your side (ps has less items), you can create a file with huge lines in it, then the following command will do:

$ cat file-with-100k-lines.txt | head -n 3

Logically, when the second command finish its job, will terminate and close its resource, the output of the pipe; then the first (still running) command noticed (when trying write to) the pipe is closed, it will terminate too.

I haven't tackled it yet. Maybe a signal handle issue, maybe not.

mitnk commented 3 years ago

Finally this issue (stuck of yes | head etc) is fixed! The last blocker on road to 1.0.0 removed :)