---
title: "A PipeWire Virtual Sink That Survives kill -9 (Linux) | CloudGuys Blog"
description: "Route Linux audio through a PipeWire virtual sink with no root, then restore the default output after kill -9. Rust code and a seven-scenario test."
url: "https://cloudguys.io/blog/pipewire-virtual-sink-survives-kill-9"
language: "en"
image: "https://cloudguys.io/_astro/cover.DUp-hUg0.jpg"
published: "2026-11-20T00:00:00.000Z"
modified: "2026-11-20T00:00:00.000Z"
---

ENGINEERING NOTES / AUDIO ENGINEERING

# A PipeWire Virtual Sink That Survives kill -9

Route all Linux audio through your own PipeWire virtual sink with no root or driver, and restore the default output after kill -9. Rust code and a kill test.

Sabbir Ahmed · · · November 20, 2026 · · · 9 min read · · · Facts checked November 8, 2026 · · · About nomus

![A PipeWire Virtual Sink That Survives kill -9](https://cloudguys.io/_astro/cover.DUp-hUg0_Z1sTo8s.webp)

On Linux, an ordinary user-session program can process every app’s audio by creating a PipeWire stream that is itself a sink, making it the configured default output, and playing the result to the real device through a second stream. The sink dies with your process. The default-output setting does not: WirePlumber persists it, so a `kill -9` leaves the user’s configuration pointing at a device that no longer exists. The fix is to write the user’s choice to disk before you replace it, and hand it back on the next start.

Here is how nomus, the real-time music filter CloudGuys builds, does both, and the kill test that exposed the bug. The code is Rust with the `pipewire` crate. PipeWire and WirePlumber facts link to their official documentation, checked on 8 November 2026. Every test result below comes from a headless container, not real hardware.

## The short answer

-   **Two streams, like PipeWire’s own loopback module:** a capture stream with `media.class = Audio/Sink` that apps play into, and a playback stream pinned to the real device.
-   **Take over by writing `default.configured.audio.sink`** in the `default` metadata, the same key desktop sound settings write.
-   **Pin the playback stream** with `target.object`, `node.dont-reconnect` and `node.dont-fallback`, or the session manager may route your output into your own sink.
-   **Save the previous default to a state file first**, atomically, then write the metadata.
-   **Hand back only if the key still names your sink.** If the user picked another device meanwhile, their choice stands.

## How do you intercept all app audio on Linux without root?

You become the default output. PipeWire is a graph of nodes; the session manager, WirePlumber on current distributions, links each new playback stream to the default sink unless the stream names another target. WirePlumber’s [linking policy](https://pipewire.pages.freedesktop.org/wireplumber/policies/linking.html) documents the key: `default.configured.audio.sink` in metadata object 0, of type `Spa:String:JSON`, with a value such as `{"name":"the-node-name"}`. If the configured node does not exist, WirePlumber picks the best available device instead.

A stream whose `media.class` is `Audio/Sink` is presented to every other client as an output device. So nomus needs no driver, no root and no kernel module. It is the same idea as PipeWire’s [loopback module](https://docs.pipewire.org/page_module_loopback.html), which passes a capture stream to a playback stream and can be used to create virtual sinks.

| Approach | Root or driver | Who owns the sink | On crash | Used by nomus |
| --- | --- | --- | --- | --- |
| `pw_stream` sink in your process, default set via metadata | No | Your process | Sink vanishes; the configured default keeps naming it (tested, below) | Yes |
| Loopback or filter-chain module in the user’s PipeWire config | No | The PipeWire daemon | Not tested by us | No: it means editing the user’s config |
| Kernel or HAL-style virtual audio driver | Yes | The system | Not tested by us | No |

## The shape

`nomus-sink` receives what the apps play, runs the engine in its process callback, and pushes the result into a ring buffer. `nomus-playback` pops from the ring and plays to the real sink. Both streams carry the same `node.group` and `node.link-group`, so PipeWire runs them in the same graph cycle and the ring only absorbs the order in which the two callbacks run. Per the [PipeWire properties manual](https://docs.pipewire.org/page_man_pipewire-props_7.html), nodes in one link group are also not linked to each other by the session manager.

The constants from `crates/nomus-system/src/linux.rs`:

```rust
const SINK_NAME: &str = state::SINK_NAME;
const CONFIGURED_SINK: &str = "default.configured.audio.sink";
const DEFAULT_SINK: &str = "default.audio.sink";
const RATE: u32 = 48_000;
/// Frames held between the sink and the playback stream before playback
/// starts. Both streams share a graph cycle, so this is only slack for the
/// order in which the two run.
const PREFILL: usize = 256;
```

## Pin the playback stream, or you build a loop

The easy mistake is in the playback stream’s properties:

```rust
"target.object" => target.name.as_str(),
"node.dont-reconnect" => "true",
"node.dont-fallback" => "true",
"node.group" => group.as_str(),
"node.link-group" => group.as_str(),
"stream.dont-remix" => "true",
```

The default is now `nomus`. If the real sink disappears and the playback stream is allowed to fall back to the default target, WirePlumber would link nomus’s output into nomus’s input. The [properties manual](https://docs.pipewire.org/page_man_pipewire-props_7.html) says `node.dont-fallback` stops the session manager from linking the node to the default target when linking to its specified target fails, and `node.dont-reconnect` stops the node from being moved to another sink when its target is destroyed (the node is destroyed too). So nothing moves the stream on its own. nomus watches for the stream entering `Error` or `Unconnected` and rebuilds the session on the new target itself. `stream.dont-remix` keeps PipeWire from changing the channel layout.

Two more choices I would keep:

-   **One thread for all PipeWire objects.** The Rust bindings’ `MainLoopRc` and `StreamRc` are `Rc`, not `Send`. nomus runs the whole session on a `nomus-pipewire` thread, and `Drop` sends a quit message and joins, so the default has been handed back before `close` returns.
-   **Let PipeWire convert formats.** Both streams offer `F32LE`, 48 kHz, FL/FR, and PipeWire converts at the edges. In a test with the graph forced to 44.1 kHz, this path reported the same ~31 ms delay as 48 kHz; nomus’s own resampler would have added more.

## Taking the default, and handing it back

Order matters here. The user’s choice goes to disk before nomus replaces it.

```rust
// Remember the user's choice on disk before replacing it, so a nomus that
// dies cannot lose it (see `recover`).
let have_metadata = graph.borrow().metadata.is_some();
let state_path = state::default_state_path();
if have_metadata {
    let path = state_path.as_deref().ok_or_else(|| Error::Platform("cannot find a state directory (HOME is not set)".into()))?;
    let saved = Saved { pid: std::process::id(), previous: original_configured.clone() };
    state::save(path, &saved)
        .map_err(|e| Error::Platform(format!("cannot save the current output device to {}: {e}", path.display())))?;
    conn.write_default(&Action::Set(SINK_NAME.into()))?;
}
armed.set(true);
```

The state file lives at `$XDG_STATE_HOME/nomus/default-sink` (else `~/.local/state/nomus/default-sink`) and is tiny:

```text
# nomus: the output device to hand back if nomus exits without restoring it.
version=1
pid=64
previous=speakers
```

It is written atomically: a temporary file, `sync_all`, `rename`, then a sync of the directory. If it cannot be written, the start fails rather than take a default it could not give back. `armed` is set only after the write, so nomus’s own change to the key is not mistaken for the user choosing another device.

On a normal stop, the policy is one pure function in `linux_state.rs`:

```rust
pub fn hand_back(configured: Option<&str>, previous: Option<&str>) -> Action {
    match configured {
        None | Some(SINK_NAME) => match previous.filter(|p| !p.is_empty() && *p != SINK_NAME) {
            Some(p) => Action::Set(p.to_string()),
            None => Action::Clear,
        },
        Some(_) => Action::Keep,
    }
}
```

If the key still reads `nomus` (or nothing), it is nomus’s to change. Any other value is a choice the user made after nomus started, so it stays. A saved device that is missing right now, such as a Bluetooth headset that is off, is still written back by name: WirePlumber plays through the best available sink and switches back when the device returns. Clearing the key would forget the choice.

## What does kill -9 leave behind?

Sound survives; configuration does not. nomus’s first crash test, on 26 September 2026 in a headless Docker container with a null sink called `speakers`, logged this:

| Moment | `default.configured.audio.sink` | effective default |
| --- | --- | --- |
| before | speakers | speakers |
| nomus running | nomus | nomus |
| after `kill -9` | nomus | speakers |
| after a normal run and stop (old build) | *(cleared)* | speakers |

WirePlumber fell back to `speakers`, so audio kept playing. But the configured key still named a sink that no longer existed, and the next normal stop cleared it because nomus had never recorded the earlier choice. On a machine with several outputs, the device the user picked was forgotten. Ctrl-C took the same path, because the CLI installed no signal handler.

After the fix, the same unchanged script ends with `configured=speakers`.

## Recovery: three places read the state file

1.  **The next start** of a session repairs a leftover before saving anything of its own.
2.  **App launch**: the desktop app runs recovery once, so opening it repairs a leftover even if the filter is never switched on.
3.  **`nomus-system recover`**, a CLI subcommand that does only that.

Recovery has one guard: another nomus that is still running. It finds any sink named `nomus`, maps it to its owner through the node’s `client.id` and that client’s `pipewire.sec.pid`, and leaves a live instance alone. A second nomus that tries to start exits with “already running”.

You can watch the key yourself while testing any virtual sink:

```bash
pw-metadata 0 default.configured.audio.sink   # the user's configured choice
pw-metadata -m                                # monitor metadata changes live
wpctl status                                  # sinks, and which is default
```

## The seven-scenario kill test

`kill-test.sh` runs in the same container with two null sinks, `speakers` and `headphones`, and a metadata monitor. The saved log (26 September 2026) ends in PASS:

| Scenario | Result |
| --- | --- |
| A. `kill -9`, then the next run | hand-back at start (`speakers`), takeover (`nomus`), `speakers` at stop |
| B. `kill -9`, then `nomus-system recover` | `speakers` restored at once; a second `recover` finds nothing |
| C. Ctrl-C (exit 130), then `recover` | `speakers` restored |
| D. `kill -9`, the user picks headphones, then a run | `headphones` kept |
| E. the user picks headphones while nomus runs | nomus rebuilds onto them; `headphones` after stop |
| F. a second nomus while one runs | the second exits 1; `recover` leaves the first alone; `speakers` after it stops |
| G. the saved device is removed before `recover` | configured `headphones`, effective `speakers`; back to `headphones` when it returns |

Scenario D is the one that guards against a “fix” that undoes the user’s own choice.

The headless smoke test also checks the audio itself. In the 48 kHz run from the same day: what the speakers received equalled nomus’s output bit for bit, the live output matched the offline engine to −77.8 dB at a 20.0 ms lag, 17.6 dB of music was removed in the pauses between words, and the log line read `before=speakers during=nomus saved=speakers after=speakers state-file-after=removed -> restored`.

## Is the ~31 ms delay real?

Partly. nomus reports the engine’s 20 ms plus two 256-frame prefills, about 31 ms. That leaves out the PipeWire quantum: each stream adds at least one quantum of buffering. The meter log implies blocks of roughly 1,000 and 2,000 frames (21 and 42 ms), but that is an inference from callback counts, not a measurement.

## Limits

-   **Pinned streams bypass the sink.** An app that targets a specific device does not follow the default.
-   **PipeWire only.** On a PulseAudio system nomus says so and stops; it needs PipeWire 0.3.49 or newer. Ubuntu 22.04 ships 0.3.48 and was tested only for that message.
-   **No real hardware yet.** Every run above is a headless container on an arm64 Mac (Ubuntu 24.04 and Debian 12 images). Desktops, Bluetooth and suspend are untested.

The nomus Linux app is in development, so treat this as a design write-up, not a release note.

## The general rule

Record what you change before you change it, and undo leftovers on the next start. nomus follows the same rule on Android, where an audio effect outlives its process. The macOS version in [Muting every app on macOS with Core Audio process taps](https://cloudguys.io/blog/mute-apps-macos-core-audio-process-taps) gets that guarantee from the OS for free. The whole architecture is in [One Rust engine, four hosts](https://cloudguys.io/blog/one-rust-engine-four-hosts), and the [nomus product page](https://cloudguys.io/products/nomus) lists the series.

## FAQ

**Do I need root or a kernel driver for a virtual sink on Linux?** No. A `pw_stream` with `media.class = Audio/Sink` in your own user process is enough, and the session manager treats it as an output device.

**What happens to the default output if the app is killed with `kill -9`?** The sink disappears, but WirePlumber keeps the configured default naming it. Audio keeps playing through the best available device, yet the user’s real choice is lost unless you saved it first.

**Does this work on PulseAudio?** No. nomus needs PipeWire 0.3.49 or newer and says so, then stops, on a PulseAudio system.

**Has this been tested on real desktops?** Not yet. All runs were headless containers (Ubuntu 24.04, Debian 12) on an arm64 Mac.

CloudGuys builds nomus. If you want to hear the engine, try the demo or the Chrome extension on the [nomus page](https://agrohi.com/nomus/).

#Linux · #PipeWire · #WirePlumber · #Rust · #nomus

Share this article

-   [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcloudguys.io%2Fblog%2Fpipewire-virtual-sink-survives-kill-9%3Futm_source%3Dlinkedin%26utm_medium%3Dsocial "Share on LinkedIn")
-   [X](https://twitter.com/intent/tweet?text=A%20PipeWire%20Virtual%20Sink%20That%20Survives%20kill%20-9&url=https%3A%2F%2Fcloudguys.io%2Fblog%2Fpipewire-virtual-sink-survives-kill-9%3Futm_source%3Dx%26utm_medium%3Dsocial "Share on X")
-   [Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fcloudguys.io%2Fblog%2Fpipewire-virtual-sink-survives-kill-9%3Futm_source%3Dreddit%26utm_medium%3Dsocial&title=A%20PipeWire%20Virtual%20Sink%20That%20Survives%20kill%20-9 "Share on Reddit")
-   [Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fcloudguys.io%2Fblog%2Fpipewire-virtual-sink-survives-kill-9%3Futm_source%3Dhackernews%26utm_medium%3Dsocial&t=A%20PipeWire%20Virtual%20Sink%20That%20Survives%20kill%20-9 "Share on Hacker News")
-   [Email](mailto:?subject=A%20PipeWire%20Virtual%20Sink%20That%20Survives%20kill%20-9&body=A%20PipeWire%20Virtual%20Sink%20That%20Survives%20kill%20-9%0A%0Ahttps%3A%2F%2Fcloudguys.io%2Fblog%2Fpipewire-virtual-sink-survives-kill-9%3Futm_source%3Demail%26utm_medium%3Dsocial "Share on Email")

BUILT AND OPERATED BY CLOUDGUYS

## nomus: real-time music filter  
Keep the voice, lose the music, on your own device.

nomus removes background music from live audio and keeps the voices, speech and singing. One Rust engine and a small neural network run in a Chrome tab, system-wide on macOS and Linux, and on Android, with 20 ms of delay and no server.

[Visit nomus ↗](https://agrohi.com/nomus/?utm_source=cloudguys_blog&utm_medium=referral&utm_campaign=pipewire-virtual-sink-survives-kill-9) [About nomus ↗](https://cloudguys.io/products/nomus)

## Structured data

```json
[
  {
    "@context": "https://schema.org",
    "@type": [
      "ProfessionalService",
      "Organization"
    ],
    "@id": "https://cloudguys.io/#organization",
    "name": "CloudGuys",
    "url": "https://cloudguys.io/",
    "logo": {
      "@type": "ImageObject",
      "url": "https://cloudguys.io/assets/logo.png",
      "width": 512,
      "height": 512
    },
    "image": "https://cloudguys.io/assets/og-image.png",
    "description": "Self-hosted software products, senior engineers embedded in client teams, and cloud security and architecture advisory across AWS, Google Cloud, Azure, Kubernetes, and infrastructure as code.",
    "email": "hello@cloudguys.io",
    "founder": {
      "@type": "Person",
      "@id": "https://cloudguys.io/authors/sabbir-ahmed#person",
      "name": "Sabbir Ahmed",
      "url": "https://cloudguys.io/authors/sabbir-ahmed"
    },
    "slogan": "Ship with confidence. Keep control.",
    "areaServed": "Worldwide",
    "hasOfferCatalog": {
      "@type": "OfferCatalog",
      "name": "CloudGuys engagements",
      "itemListElement": [
        {
          "@type": "Offer",
          "itemOffered": {
            "@type": "Service",
            "name": "Embedded engineers",
            "url": "https://cloudguys.io/services/embedded-engineers",
            "provider": {
              "@id": "https://cloudguys.io/#organization"
            }
          }
        },
        {
          "@type": "Offer",
          "itemOffered": {
            "@type": "Service",
            "name": "Cloud security assessment",
            "url": "https://cloudguys.io/services/cloud-security-assessment",
            "provider": {
              "@id": "https://cloudguys.io/#organization"
            }
          }
        },
        {
          "@type": "Offer",
          "itemOffered": {
            "@type": "Service",
            "name": "Cloud architecture review",
            "url": "https://cloudguys.io/services/cloud-architecture-review",
            "provider": {
              "@id": "https://cloudguys.io/#organization"
            }
          }
        },
        {
          "@type": "Offer",
          "itemOffered": {
            "@type": "Service",
            "name": "Security remediation",
            "url": "https://cloudguys.io/services/security-remediation",
            "provider": {
              "@id": "https://cloudguys.io/#organization"
            }
          }
        }
      ]
    },
    "knowsAbout": [
      "DevOps",
      "Kubernetes",
      "Terraform",
      "Cloud migration",
      "Cloud cost optimization",
      "GitOps",
      "Site reliability engineering",
      "Kubernetes dashboard",
      "AI SRE",
      "Kubernetes troubleshooting",
      "AWS",
      "Google Cloud",
      "Azure"
    ],
    "contactPoint": {
      "@type": "ContactPoint",
      "contactType": "sales",
      "email": "hello@cloudguys.io",
      "availableLanguage": [
        "English"
      ],
      "areaServed": "Worldwide"
    },
    "sameAs": [
      "https://www.linkedin.com/company/agrohitech",
      "https://berth.cloudguys.io",
      "https://tele.cloudguys.io"
    ],
    "owns": [
      {
        "@type": "SoftwareApplication",
        "@id": "https://berth.cloudguys.io/#software",
        "name": "Berth",
        "applicationCategory": "DeveloperApplication",
        "operatingSystem": "Kubernetes",
        "url": "https://berth.cloudguys.io",
        "description": "Berth is a self-hosted Kubernetes dashboard with a read-only AI SRE: endpoint health, capacity planning, guided app exposure, and evidence-based troubleshooting, run in your own cluster."
      },
      {
        "@type": "SoftwareApplication",
        "@id": "https://tele.cloudguys.io/#software",
        "name": "Tele",
        "applicationCategory": "CommunicationApplication",
        "operatingSystem": "Web",
        "url": "https://tele.cloudguys.io",
        "description": "Tele is real-time audio and video call infrastructure: a meeting API for embedding calls in your own application and a managed workspace for teams, deployable in your own cloud or private environment."
      }
    ]
  },
  {
    "@context": "https://schema.org",
    "@type": "WebSite",
    "@id": "https://cloudguys.io/#website",
    "url": "https://cloudguys.io/",
    "name": "CloudGuys",
    "description": "Self-hosted software, embedded engineers and cloud security advisory for teams that run their own platform.",
    "publisher": {
      "@id": "https://cloudguys.io/#organization"
    },
    "inLanguage": "en"
  },
  {
    "@context": "https://schema.org",
    "@type": "BlogPosting",
    "@id": "https://cloudguys.io/blog/pipewire-virtual-sink-survives-kill-9#article",
    "headline": "A PipeWire Virtual Sink That Survives kill -9",
    "description": "Route Linux audio through a PipeWire virtual sink with no root, then restore the default output after kill -9. Rust code and a seven-scenario test.",
    "image": "https://cloudguys.io/_astro/cover.DUp-hUg0.jpg",
    "datePublished": "2026-11-20T00:00:00.000Z",
    "dateModified": "2026-11-20T00:00:00.000Z",
    "author": {
      "@type": "Person",
      "@id": "https://cloudguys.io/authors/sabbir-ahmed#person",
      "name": "Sabbir Ahmed",
      "jobTitle": "Founder",
      "url": "https://cloudguys.io/authors/sabbir-ahmed",
      "worksFor": {
        "@id": "https://cloudguys.io/#organization"
      },
      "sameAs": [
        "https://github.com/by-sabbir"
      ]
    },
    "publisher": {
      "@id": "https://cloudguys.io/#organization"
    },
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": "https://cloudguys.io/blog/pipewire-virtual-sink-survives-kill-9"
    },
    "articleSection": "Audio Engineering",
    "keywords": "Linux, PipeWire, WirePlumber, Rust, nomus",
    "inLanguage": "en",
    "about": {
      "@type": "SoftwareApplication",
      "@id": "https://agrohi.com/nomus/#software",
      "name": "nomus",
      "url": "https://agrohi.com/nomus"
    }
  },
  {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
      {
        "@type": "ListItem",
        "position": 1,
        "name": "Home",
        "item": "https://cloudguys.io/"
      },
      {
        "@type": "ListItem",
        "position": 2,
        "name": "Blog",
        "item": "https://cloudguys.io/blog"
      },
      {
        "@type": "ListItem",
        "position": 3,
        "name": "A PipeWire Virtual Sink That Survives kill -9",
        "item": "https://cloudguys.io/blog/pipewire-virtual-sink-survives-kill-9"
      }
    ]
  },
  {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    "@id": "https://cloudguys.io/blog/pipewire-virtual-sink-survives-kill-9#faq",
    "mainEntity": [
      {
        "@type": "Question",
        "name": "Do I need root or a kernel driver for a virtual sink on Linux?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "No. A pw_stream with media.class = Audio/Sink in your own user process is enough, and the session manager treats it as an output device."
        }
      },
      {
        "@type": "Question",
        "name": "What happens to the default output if the app is killed with kill -9?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "The sink disappears, but WirePlumber keeps the configured default naming it. Audio keeps playing through the best available device, yet the user's real choice is lost unless you saved it first."
        }
      },
      {
        "@type": "Question",
        "name": "Does this work on PulseAudio?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "No. nomus needs PipeWire 0.3.49 or newer and says so, then stops, on a PulseAudio system."
        }
      },
      {
        "@type": "Question",
        "name": "Has this been tested on real desktops?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "Not yet. All runs were headless containers (Ubuntu 24.04, Debian 12) on an arm64 Mac. CloudGuys builds nomus. If you want to hear the engine, try the demo or the Chrome extension on the nomus page."
        }
      }
    ]
  }
]
```
