Skip to content

[windows] try to fix hanging processes#134

Merged
ckreibich merged 2 commits into
zeek:masterfrom
mamaorha:ms/windows/hang
Mar 19, 2026
Merged

[windows] try to fix hanging processes#134
ckreibich merged 2 commits into
zeek:masterfrom
mamaorha:ms/windows/hang

Conversation

@mamaorha
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Member

@ckreibich ckreibich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor nit Maor, and one question since I don't know the Windows world in /proc at all.

Comment thread btest-bg-run-helper Outdated
# Also record the child's MSYS PID. btest-bg-wait can use this to
# look up the *current* Windows PID via /proc at kill time, which is
# more reliable than .winpid because exec may change the Windows PID.
echo $pid >.child_pid
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're only using this on Windows, how would you feel about moving this up into the the if-block and naming the file ".winchildpid" or some such? I bring this up mainly because Windows support adds a fair bit of complexity to these already hairy scripts, so it helps to explain why the files are there.

Comment thread btest-bg-wait
fi
fi

# The .winpid captured at startup may hold a stale
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a "may or may not" for unknown reasons (or perhaps a race condition), or does the /proc/$cpid/winpid case always hold true for Cygwin but not elsewhere and so this is a actually a Cygwin-specific check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Unix, exec() replaces the process image but preserves the PID — that's a fundamental guarantee. Cygwin/MSYS2 can't do that because Windows has no native exec().
Instead, the runtime spawns a new Windows process and terminates the old one. So after exec():

  • MSYS/Cygwin PID → stays the same (virtual, tracked by the runtime)
  • Windows PID → changes (it's a brand-new native process)

This is exactly why the live /proc/$pid/winpid lookup is needed — .winpid captured the pre-exec Windows PID, which is now dead

Copy link
Copy Markdown
Member

@ckreibich ckreibich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Maor!

@ckreibich ckreibich merged commit a2eddd3 into zeek:master Mar 19, 2026
22 checks passed
@mamaorha mamaorha deleted the ms/windows/hang branch March 19, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants