# Passing FDs/handles between processes on Unix and Windows -- a comparison

DevFeed: [Passing FDs/handles between processes on Unix and Windows -- a comparison](<https://devfeed.tech/articles/passing-fds-handles-between-processes-on-unix-and-windows-a-comparison-21573.md>)

Original publisher: [Read original article](<http://lackingrhoticity.blogspot.com/2015/05/passing-fds-handles-between-processes.html>)

Author: Mark Seaborn (noreply@blogger.com)

Published: 2015-05-24T20:57:00Z

Content type: article

Language: en

Sources: [Mark Seaborn](<https://devfeed.tech/sources/mark-seaborn.md>)

Topics: [Unix](<https://devfeed.tech/topics/unix.md>), [Windows](<https://devfeed.tech/topics/windows.md>), [Processes](<https://devfeed.tech/topics/processes.md>), [API](<https://devfeed.tech/topics/api.md>), [systems](<https://devfeed.tech/topics/systems.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [comparison](<https://devfeed.tech/tags/comparison.md>), [processes](<https://devfeed.tech/tags/processes.md>), [programming](<https://devfeed.tech/tags/programming.md>), [systems](<https://devfeed.tech/tags/systems.md>), [unix](<https://devfeed.tech/tags/unix.md>), [windows](<https://devfeed.tech/tags/windows.md>)

## AI overview

This article compares how Unix file descriptors and Windows handles are represented and passed between processes. It explains their shared distinction between numeric identifiers and underlying objects, then contrasts Unix socket-based descriptor passing with Windows use of the DuplicateHandle API.

## Source excerpt

Handles on Windows are analogous to file descriptors (FDs) on Unix, and both can be passed between processes. However, the way in which handles/FDs can be passed between processes is quite different on Unix and Windows. In this blog post I'll explain the difference. You might find this useful if you are familiar with systems programming on either Unix or Windows but not both. Similarities I'll first explain what's the same on Unix and Windows. Both OSes have a distinction between FD/handle numbers and FD/handle objects. On both Windows and Unix, each process has its own FD/handle table which maps from FD/handle numbers to FD/handle objects: FD numbers are indexes into the FD table. On Unix, an FD number is an int. Windows uses the HANDLE type for handle numbers. Though HANDLE is typedef'd to void *, a HANDLE is really just a 32-bit index. (Windows does not use a HANDLE as a pointer into the process's address space.) FD objects are what FD numbers map to. User code never gets to see FD objects directly: it can only manipulate them via FD numbers. Multiple FD numbers can map to the same FD object. FD objects are (mostly) reference counted. All of this applies to handles on Windows too. Note: Some people use the alternative terminology that a "file description" refers to the underlying object while "file descriptor" refers to the number. I prefer to add "number" or "object" as a suffix as the way to disambiguate -- it is more explicit, and the term "file description" is not often used. Differences The key difference between Unix and Windows is this: On Unix, FD objects can be sent via sockets in messages. On Windows, handle objects cannot be sent in messages; only handle numbers can. Windows fills this gap by allowing one process to read or modify another process's handle table synchronously using the DuplicateHandle() API. Using this API involves one process dealing with another process's handle numbers. In contrast, Unix has no equivalent to DuplicateHandle(). A Unix