The Process Management Utilities provide a cross-platform abstraction layer for spawning external processes, capturing their output, and querying process information. This foundation library enables fastfetch to execute external commands for detection purposes (e.g., querying package managers or GPU drivers) and traverse the process tree to identify parent processes such as terminal emulators and shells.
Sources: src/common/processing.h1-52
The FFProcessHandle structure provides a platform-agnostic handle to a spawned process and its output pipe. The structure uses conditional compilation to abstract the differences between Windows handles and Unix file descriptors.
| Platform | pid Field | pipeRead Field | Purpose |
|---|---|---|---|
| Windows | void* (HANDLE) | void* (HANDLE) | Uses kernel object handles for processes and anonymous pipes src/common/processing.h11-12 |
| Unix/Linux | pid_t | int | Uses integer process IDs and file descriptors src/common/processing.h14-15 |
Sources: src/common/processing.h9-17
The process management API provides a two-stage workflow for executing external commands: spawning the process with ffProcessSpawn() and reading its output with ffProcessReadOutput().
Sources: src/common/processing.h19-20
On Windows, ffProcessSpawn performs complex command-line escaping via argvToCmdline to ensure arguments are passed correctly to the underlying CreateProcessW API src/common/impl/processing_windows.c14-49 It utilizes named pipes (e.g., \\.\pipe\FASTFETCH-%u-%u) to capture output, allowing for overlapped I/O and timeouts src/common/impl/processing_windows.c55-68
ffProcessReadOutput on Windows implements a timed wait using NtWaitForSingleObject and NtReadFile src/common/impl/processing_windows.c174-187 If the processingTimeout is exceeded, it calls terminateChildProcess to forcefully end the task src/common/impl/processing_windows.c195-197
Sources: src/common/impl/processing_windows.c51-141 src/common/impl/processing_windows.c154-203
Spawns a new process with the specified arguments and creates a pipe to capture either stdout or stderr.
Reads all output from the pipe, waits for the process to terminate, and destroys the handle internally. This function consumes the handle, making it invalid after the call.
The API provides inline helper functions that combine spawning, reading, and cleanup into a single operation:
| Function | Purpose | Implementation Detail |
|---|---|---|
ffProcessAppendStdOut | Captures stdout | Calls ffProcessSpawn(argv, false, ...) then ffStrbufTrimRightSpace src/common/processing.h22-32 |
ffProcessAppendStdErr | Captures stderr | Calls ffProcessSpawn(argv, true, ...) then ffStrbufTrimRightSpace src/common/processing.h34-44 |
Fastfetch requires the ability to inspect running processes to determine the environment (e.g., which terminal is running).
src/common/processing.h47
Retrieves parent PID (ppid), process name (pname), executable path (exe), and a GUI flag.
ffProcessGetInfoLinux retrieves process name and executable paths via /proc symlinks src/common/processing.h49ffProcessGetBasicInfoLinux retrieves name, ppid, and tty by parsing /proc/[pid]/stat src/common/processing.h50In addition to process management, fastfetch provides a lightweight threading wrapper in common/thread.h to handle concurrent detection tasks.
The implementation abstracts pthread on Unix and HANDLE (via _beginthreadex) on Windows src/common/thread.h13-39
| Feature | Windows Implementation | Unix Implementation |
|---|---|---|
| Mutex | SRWLOCK src/common/thread.h12 | pthread_mutex_t or os_unfair_lock src/common/thread.h43-48 |
| Creation | _beginthreadex src/common/thread.h17 | pthread_create src/common/thread.h54 |
| Join | NtWaitForSingleObject src/common/thread.h24 | pthread_join or pthread_timedjoin_np src/common/thread.h70-79 |
Sources: src/common/thread.h5-82
For modules requiring low-level terminal communication (e.g., querying font names or terminal colors), ffGetTerminalResponse provides a mechanism to send escape sequences and parse the response.
src/common/impl/io_unix.c151-223 This function:
/dev/tty for raw I/O src/common/impl/io_unix.c155ICANON and ECHO to read raw responses src/common/impl/io_unix.c163poll or select to wait for a response src/common/impl/io_unix.c169-185vsscanf src/common/impl/io_unix.c208Sources: src/common/impl/io_unix.c151-223
The utilities follow a standard pattern for error reporting:
const char* representing a static error message or NULL on success src/common/processing.h19-20ffProcessReadOutput is responsible for internal cleanup of the FFProcessHandle, ensuring that callers do not leak OS handles if they follow the standard workflow src/common/processing.h20BluetoothFindFirstRadio failure on Windows) src/detection/bluetoothradio/bluetoothradio_windows.c73Sources: src/common/processing.h1-52 src/detection/bluetoothradio/bluetoothradio_windows.c54-107
Refresh this wiki