POSIX Is Not import std (Manx)

Importing the Standard Library covered the CMake setup this chapter and several that follow all share. import std; is strictly the ISO C++ standard library — nothing outside the standard itself. pid_t and ::getpid(), familiar as they are on any POSIX system, belong to POSIX and glibc, not to C++. Reaching for a process ID is enough to need a traditional header again, even in a translation unit that otherwise imports std.

 1 module;
 2 
 3 #include <sys/types.h> // pid_t is POSIX, not ISO C++ -- import std has no
 4 #include <unistd.h>    // notion of it. ::getpid() is POSIX too.
 5 
 6 export module Manx;
 7 
 8 import std;
 9 
10 export auto meow() -> void {
11    pid_t const pid{getpid()};
12    std::println("The Manx cat says 'Meow' (pid {})", static_cast<long>(pid));
13 }

The pattern is the general one for anything import std; doesn’t cover: a global module fragment (lines 1-4) supplies whatever isn’t part of the standard itself, and import std; (line 8) supplies everything that is. pid_t (line 11) and getpid() (line 11) come from <sys/types.h> and <unistd.h> exactly as they would in a header-based build — POSIX facilities never had anything to do with import std;’s scope, and nothing about modules changes that.

This is worth stating plainly for anyone porting an existing codebase to import std;: any code that talks to the operating system directly — process and thread APIs, file descriptors, sockets, signal handling beyond what <csignal>’s C++ wrapper provides — keeps its traditional headers no matter how much of the rest of the file switches over.

Manx builds exactly the way Importing the Standard Library showed, with Manx.cppm in place of the generic example.