rkitover / vimpager

Use Vim as PAGER

Home Page:http://www.vim.org/scripts/script.php?script_id=1723

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Leftover 'cat' process after vimcat

achilleas-k opened this issue · comments

It took me a while to narrow this down and I haven't figured it out completely yet, but sometimes the last cat in the subshell with the loop is not killed and does not exit after the vimcat process is complete.

I'm referring to the following line:

vimpager/vimcat

Line 305 in fdc74aa

cat "$out_fifo"

It appears the subshell is properly killed at the end ($tail_pid), but not the absolute last cat in the loop.

I made the following changes to the vimcat script in order to figure out which exact invocation of cat was staying behind:

diff --git a/vimcat b/vimcat
index b599d6c..41a2795 100755
--- a/vimcat
+++ b/vimcat
@@ -36,6 +36,7 @@ else
 fi
 
 quit() {
+    echo "Killing v${vim_pid} p${pipeline_pid} t${tail_pid}"
     (
         kill "$vim_pid" >/dev/null 2>&1
         do_sleep 100
@@ -302,7 +303,9 @@ do
 
         (
             while :; do
-                cat "$out_fifo"
+                cat "$out_fifo" & cat_pid=$!
+                wait ${cat_pid}
+                echo "cat_pid: ${cat_pid}"
             done
         ) &
         tail_pid=$!

And use this script to test:

#!/usr/bin/env bash

echo "'cat' processes before:"
pgrep -af vimcat_out.fifo
echo "-----"

./vimcat << EOF
Just some sample text
Line 2
Line 3
EOF

echo "'cat' processes after:"
pgrep -af vimcat_out.fifo
echo "-----"

Running the script produces:

'cat' processes before:
-----
Just some sample text
cat_pid: 12135
              Line 2
Line 3
cat_pid: 12169
Killing v12136 p12140 t12134
'cat' processes after:
12172 cat /tmp/vimcat_12125/vimcat_out.fifo
-----

and each subsequent run adds another leftover process. Changing the input into vimcat to a file or anything else (even a single character) has the same issue. I made it multiple lines to show that only the last $cat_pid stays running.

I guess a workaround (or even a solution?) would be to keep $cat_pid around and kill it in quit() along with all the other processes, but I'm wondering if there's a cleaner way. I'd also be curious to know why this is happening and if it is happening for anyone else.


This occurs on several machines, all with the following information:
OS: Arch Linux
Shell: zsh 5.5.1 (reproducible with bash 4.4.19)
Vim: 8.1
Vimcat: 2.06-351-gfdc74aa (current master)