# I closed the terminal that had the kak server, now the clients are sad :(

**URL:** <https://discuss.kakoune.com/t/i-closed-the-terminal-that-had-the-kak-server-now-the-clients-are-sad/2269>\
**Category:** Uncategorized\
**Created:** [July 31, 2023, 2:07pm UTC](https://discuss.kakoune.com/t/i-closed-the-terminal-that-had-the-kak-server-now-the-clients-are-sad/2269 "2023-07-31T14:07:15Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![krobelus](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/krobelus/32/616_2.png) [@krobelus](https://discuss.kakoune.com/u/krobelus)\
**Post date:** [September 1, 2023, 5:30am UTC](https://discuss.kakoune.com/t/i-closed-the-terminal-that-had-the-kak-server-now-the-clients-are-sad/2269/21 "2023-09-01T05:30:31Z")

</div>

sounds about right. I prefer something similar but with `-d` so when I close the last client, the server exits

---

<div class="post-metadata">

**Author:** ![schickm](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schickm/32/79_2.png) [@schickm](https://discuss.kakoune.com/u/schickm)\
**Post date:** [September 2, 2023, 12:02am UTC](https://discuss.kakoune.com/t/i-closed-the-terminal-that-had-the-kak-server-now-the-clients-are-sad/2269/22 "2023-09-02T00:02:37Z")

</div>

Yeah, it is nice that `-d` does that for you. For me though, I’m a big fan of [suspend-and-resume](https://github.com/mawww/kakoune/wiki/Integrating-Other-CLI-apps). If I use `-d`, then if I suspend the initial client that kicked off the session, then my other clients become unresponsive since the server process has been suspended.

Maybe I need to switch out the suspend-and-resume for just popping a new terminal onto of my existing kakoune client, then I could have the best of both worlds.

---

<div class="post-metadata">

**Author:** ![krobelus](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/krobelus/32/616_2.png) [@krobelus](https://discuss.kakoune.com/u/krobelus)\
**Post date:** [September 4, 2023, 3:33pm UTC](https://discuss.kakoune.com/t/i-closed-the-terminal-that-had-the-kak-server-now-the-clients-are-sad/2269/23 "2023-09-04T15:33:56Z")

</div>

sorry I meant _without_ `-d`

> If I use `-d`, then if I suspend the initial client that kicked off the session, then my other clients become unresponsive since the server process has been suspended.

This is because you didn’t add `setsid` to your `kak -d` invocation. Without `setsid`, `kak -d` will still have the same process group as the parent shell, and it will be suspended collaterally by `SIGSTOP` when you press Ctrl-Z.

Either way, usually you don’t need `-d`; Kakoune will daemonize automatically on Ctrl-Z. So the simple thing is to run something to the effect of `kak -s foo "$@" || kak -c foo "$@"`

There is one edge case - if you hit Ctrl-Z while there is no other client, new clients will hang. This is tracked in [[BUG] ctrl-z does not background the server · Issue #4957 · mawww/kakoune · GitHub](https://github.com/mawww/kakoune/issues/4957)  
Not sure if we want to fix that, there is a working patch in any case

---

<div class="post-metadata">

**Author:** ![schickm](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schickm/32/79_2.png) [@schickm](https://discuss.kakoune.com/u/schickm)\
**Post date:** [September 8, 2023, 7:07pm UTC](https://discuss.kakoune.com/t/i-closed-the-terminal-that-had-the-kak-server-now-the-clients-are-sad/2269/24 "2023-09-08T19:07:14Z")

</div>

Interesting, the inner workings of terminals/shells is pretty neat.

I wanted to avoid using `setsid` because it was something extra I had to install for OSX, and when I saw `disown` seeming to work, I moved on. But, clearly `setsid` is the way to go.

Thanks for all the advice, and I’ll be sure to leave that wiki page alone!

[Previous page](https://discuss.kakoune.com/t/i-closed-the-terminal-that-had-the-kak-server-now-the-clients-are-sad/2269.md?page=1)
