<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/what-the-double-fork--fahvhoj9m" -->

---
title: what the double-fork? | daily.dev
description: A deep dive into the double-fork technique used to create robust POSIX daemons. Explains why a single fork and setsid() isn't enough — a session leader can...
canonical: https://daily.dev/posts/what-the-double-fork--fahvhoj9m
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: what the double-fork? | daily.dev
og:description: A deep dive into the double-fork technique used to create robust POSIX daemons. Explains why a single fork and setsid() isn't enough — a session leader can...
og:url: https://daily.dev/posts/what-the-double-fork--fahvhoj9m
og:image: https://api.daily.dev/og/posts/FAhVHoj9M.png
og:image:alt: what the double-fork?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# what the double-fork?

**[Lobsters](https://daily.dev/sources/lobsters)** · 6 min read · 0 upvotes · 0 comments

## Summary

A deep dive into the double-fork technique used to create robust POSIX daemons. Explains why a single fork and setsid() isn't enough — a session leader can still acquire a controlling terminal — and how a second fork produces a grandchild process that is not the session leader, making it permanently unable to acquire a terminal. Also covers the cleanup steps that follow: redirecting stdin/stdout/stderr to /dev/null, closing inherited file descriptors, and why chdir and umask were skipped in the zmx implementation. Includes a visual diagram of the PID/SID/PGID state through each fork.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://bower.sh/what-the-double-fork>

## Similar posts on daily.dev

- [Moving beyond fork\(\) \+ exec\(\)](https://daily.dev/posts/moving-beyond-fork-exec--glbt7ntef) · Lobsters · 0 upvotes · 0 comments
- [Python Multiprocessing Spawn vs Fork: How Processes Are Born](https://daily.dev/posts/python-multiprocessing-spawn-vs-fork-how-processes-are-born-iopkwgrcs) · Medium · 0 upvotes · 0 comments

---

Tags: [#linux](https://daily.dev/tags/linux), [#zig](https://daily.dev/tags/zig)

[View this post on daily.dev](https://daily.dev/posts/what-the-double-fork--fahvhoj9m)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"what the double-fork?","url":"https://daily.dev/posts/what-the-double-fork--fahvhoj9m","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/what-the-double-fork--fahvhoj9m"},"datePublished":"2026-08-01T14:52:37.626Z","dateModified":"2026-08-01T20:12:41.707Z","description":"A deep dive into the double-fork technique used to create robust POSIX daemons. Explains why a single fork and setsid() isn't enough — a session leader can...","image":"https://media.daily.dev/image/upload/s--VDukGCjf--/f_auto/v1722860399/public/Placeholder%2002","thumbnailUrl":"https://media.daily.dev/image/upload/s--VDukGCjf--/f_auto/v1722860399/public/Placeholder%2002","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/what-the-double-fork--fahvhoj9m","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"linux,zig","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"what the double-fork?"}]}
```

