Skip to main content
⚑ OpenDevDocs
Fundamentals
fundamentalssystemGuideIntermediate

Operating System Processes and Signals

Understanding OS processes: PIDs, memory boundaries, background daemons, exit codes, and Unix signals (SIGINT, SIGTERM, SIGKILL).

Verified: 2026-09-30
Platforms:
all
#processes#linux#pid#signals#system

Operating System Processes and Signals

A process is an active instance of a running computer program with its own isolated memory space, file descriptors, and thread execution context.


1. Process IDs (PIDs) and Lifecycle

Every time you execute a command, script, or server, the operating system assigns it a unique integer called a Process ID (PID).

[ Kernel (PID 0) ] ──► [ systemd / launchd (PID 1) ]
                              β”‚
                              β”œβ”€β–Ί [ Nginx Server (PID 1024) ]
                              └─► [ Node.js App (PID 8492) ]
                                        β”‚ (Spawns worker child process)
                                        └─► [ Worker (PID 8493) ]

2. Process Inspection Commands

CommandActionExample
ps auxView all active processes across systemps aux | grep node
top / htopInteractive real-time CPU & memory monitorhtop
lsof -i :<port>Find the process listening on a specific network portlsof -i :3000
kill -<SIGNAL> <PID>Send an OS signal to terminate or interrupt a processkill -15 8492
killall <name>Kill all processes matching binary namekillall node

3. Standard Unix Signals

Operating systems communicate lifecycle events to processes using Signals:

SignalNumberNameAction / Behavior
SIGINT2InterruptTriggered when user presses Ctrl + C in terminal. Gracefully stops program.
SIGTERM15TerminatePolite shutdown request (default for kill). Allows app to close DB connections and finish active requests.
SIGKILL9Force KillImmediate uncatchable termination by kernel. Process cannot cleanup.
SIGHUP1HangupTerminal closed, or signals service to reload configuration without restart.

4. Graceful Shutdown in Node.js

Production servers should intercept termination signals to finish active HTTP requests and close database connections cleanly:

import http from "node:http";

const server = http.createServer((req, res) => {
  res.end("OK");
});

server.listen(3000, () => console.log("Server listening on 3000"));

// Listen for shutdown signals
function gracefulShutdown(signal) {
  console.log(`Received ${signal}. Closing HTTP server gracefully...`);
  server.close(() => {
    console.log("HTTP server closed. Database connections released.");
    process.exit(0);
  });

  // Force close if cleanup takes longer than 10 seconds
  setTimeout(() => {
    console.error("Forced termination due to timeout.");
    process.exit(1);
  }, 10000);
}

process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
process.on("SIGINT", () => gracefulShutdown("SIGINT"));

On this page