# test.TestServer.daemon_state

- **Module:** test.TestServer
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/test.rs#L838
- **Page:** https://libtmux.org/reference/rs/test-testserver-daemon_state/

```
test.TestServer.daemon_state(mut) -> DaemonState
```

Report whether the daemon is still running, and how it ended if not.

Takes `&mut self` because reading the fate of a daemon that has exited
reaps it; the guard then skips the signalling it no longer needs and
still sweeps the panes the daemon left behind. Calling this on a
running daemon changes nothing and costs one `waitpid`.

## Example

```rust
use std::time::Duration;

use libtmux::{Command, test::{DaemonState, TestServer, retry_until}};

let mut guard = TestServer::new().await?;
guard.session("work").await?;
guard.server().cmd(Command::new("kill-server")).await.ok();

// tmux stops answering on the socket before the kernel has a status
// for the process behind it, so this is a wait rather than a reading.
retry_until(Duration::from_secs(5), async || {
    !guard.daemon_state().is_running()
})
.await?;
assert!(matches!(guard.daemon_state(), DaemonState::Gone(_)));

guard.shutdown().await?;
```
