Desktop process lifecycle
Manages app-owned processes and window transitions without terminating unrelated programs or depending on shell environments.
desktop-process-lifecycle
See how it helpsWhen is it useful?
Use when quitting leaves child processes behind or GUI launch cannot locate tools.
What does it help you do?
- Tracks spawned processes and shuts down their owned process trees.
- Resolves executable paths explicitly and passes arguments without shell interpolation.
- Handles single-instance behavior, window lifecycle and sleep/wake recovery.
Try asking this
Fix an app-owned local server surviving quit, while preserving a separate server started by the user. Start both servers, quit the app and inspect process ownership. Only the app's process tree should stop, and reopening should not reuse stale state.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Process & Application Lifecycle
Desktop applications must manage their entire process tree reliably across cold start, window close/reopen, OS sleep/wake, crashes, and application quit—without leaving orphaned servers, locked SQLite databases, or zombie CLI processes behind.
Child Process & Ownership Discipline
- Track only the processes your app spawned:
- Record the
ChildProcesshandle andpid(plus process group / Job Object) of every embedded server, worker, or CLI task launched by the application. - Never run blanket
killall nodeortaskkill /IM node.exe, which destroys the user's unrelated development servers or IDE processes!
- Record the
- Clean Cross-Platform Process Tree Termination:
- On macOS/Linux: spawn long-running tool/worker trees in their own process group or send
SIGTERMto the child and its descendants, wait a bounded drain window (e.g., 3s–5s) for in-flight SQLite transactions or state checkpoints to flush, and escalate toSIGKILLonly if still alive. - On Windows:
child.kill()terminates only the immediate process, leaving grand-child processes alive. Use Windows Job Objects (JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE) ortaskkill /PID <pid> /T /Fon timeout so the entire process tree exits when the desktop app closes or crashes.
- On macOS/Linux: spawn long-running tool/worker trees in their own process group or send
- Never interpolate shell strings:
- Spawn processes with
execFile/spawn(binaryPath, argsArray, { shell: false, windowsHide: true })so file paths containing spaces, quotes, or Unicode characters (C:\Users\Gábor Laczkovszki\My Project) never break or inject shell commands.
- Spawn processes with
GUI Environment & PATH Resolution on macOS / Windows
When a user launches a macOS .app from Finder/Dock/Spotlight, the process inherits launchd's minimal PATH (/usr/bin:/bin:/usr/sbin:/sbin)—not their interactive shell PATH where Homebrew (/opt/homebrew/bin), nvm, fnm, volta, pyenv, or ~/.local/bin live:
- Resolve the user's login shell environment once at startup (e.g., invoking
$SHELL -ilc 'env -0'with a short timeout on macOS/Linux and augmenting well-known tool paths like/opt/homebrew/bin,/usr/local/bin,~/.local/bin) so external CLIs (git,claude,codex) are found reliably.
Window Lifecycle, Single-Instance Lock & Sleep/Wake
- Single-instance coordination: Acquire a single-instance lock (
app.requestSingleInstanceLock()in Electron ortauri-plugin-single-instance) before initializing the database or local server. When a second instance is launched (e.g., via deep link or file association), forward the URL/argv to the primary instance, focus its window, and exit the second instance immediately. - Explicit Window Close vs. App Quit:
- On macOS, closing the last window (
window-all-closed) conventionally keeps the app active in the Dock (activatere-opens the window), whereasCmd+Q(before-quit) initiates full shutdown. - Before quitting or applying an update while a task is running, either flush/checkpoint gracefully or prompt the user if an unrecoverable operation is in flight.
- On macOS, closing the last window (
Included files 1
SKILL.md
About this skill package
desktop-process-lifecycle
desktop-process-lifecycle: Build desktop apps with reliable native boundaries, local data, process lifecycle, packaging and update behavior.
Show less
desktop-process-lifecycle
desktop-process-lifecycle: Build desktop apps with reliable native boundaries, local data, process lifecycle, packaging and update behavior.
Includes the complete skill and its supporting files (1 files). The exact authored scope is preserved below.
Original skill description (source language)
Use when managing desktop application startup, child processes, embedded servers, GUI PATH and environment resolution, window close vs. quit behavior, single-instance locks, or clean shutdown.
Install the skill, review its source and trust settings, then enable it for the relevant project or agent.
Requirements
- Orqestria installed on your computer.
