# terminal: Actually close process groups when the terminal is closed \(\#61467\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/6297c88f428a99741a7bfb33f31dfe98123bb8e4)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 6297c88f428a99741a7bfb33f31dfe98123bb8e4

Requested commit: 6297c88f428a99741a7bfb33f31dfe98123bb8e4

Commit: 6297c88f428a99741a7bfb33f31dfe98123bb8e4

Tree: 045cfb7854fe2ad36df51f4b3beb8e77f0c56c01

Author: Finn Eitreim

Committer: GitHub

## Message

```
terminal: Actually close process groups when the terminal is closed (#61467)

# Objective

Closes #47412

Currently, processes that ignore SIGHUP/SIGTERM will not be killed when
the terminal is closed or Zed is closed.

## Solution

We need to follow up on the processes to ensure that they have been
properly killed BEFORE zed closes fully. We send SIGTERM then 100ms
later send SIGKILL, this gives programs some time to exit gracefully
before being SIGKILL'd.

## Testing

I tested it by both closing the terminal pane and closing zed
completely, both worked. There is a new test added as well. The best way
to test it is with the reproduction in this comment:

https://github.com/zed-industries/zed/issues/47412#issuecomment-4596563655

I only tested this on MacOS 27. It might be worth testing on linux, but
also mac/linux behavior here should be quite similar. Windows behavior
as well should be unchanged but could be worth testing.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments

Okay there is an unsafe block in this PR, but its just being moved from
one location to another, and it didn't originally have a comment, I
assume because its just a libc call so its pretty clear.

- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Showcase

Video showcasing the new behavior:


https://github.com/user-attachments/assets/b2b8cb0c-0648-41b4-b940-91c466aeaab3



---

Release Notes:

- Terminal: Prevents processes from being left alive when the terminal
is closed.
```

## Parents

- [40dc154a7cc28270d2319873b0881ef053dc22b9](https://git.cafe/gitcafe/zed/commit/40dc154a7cc28270d2319873b0881ef053dc22b9?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/6297c88f428a99741a7bfb33f31dfe98123bb8e4?format=markdown)
