warning linux

Linux Exit Code 130 - Interrupted (SIGINT)

Understanding Linux exit code 130 - the process was terminated by SIGINT, typically by pressing Ctrl+C.

What It Means

Exit code 130 (128 + 2) indicates that the process was terminated by SIGINT (signal 2). This is most commonly triggered when a user presses Ctrl+C in the terminal, which sends SIGINT to the foreground process.

SIGINT is a polite request to stop — unlike SIGKILL, the process can catch it and perform cleanup before exiting.

Common Causes

  • User pressed Ctrl+C to stop a running command
  • A parent process sent SIGINT to its children
  • A script was interrupted during execution
  • CI/CD pipeline cancelled a running job
  • Docker sent SIGINT during container stop

How to Fix

Handle SIGINT gracefully in bash

#!/bin/bash

cleanup() {
  echo -e "\nInterrupted! Cleaning up..."
  rm -f /tmp/my-tempfile
  exit 130  # Preserve the exit code
}

trap cleanup SIGINT

echo "Press Ctrl+C to stop..."
while true; do
  # Long-running work
  sleep 1
done

Handle in Node.js

const server = require('http').createServer(app);

process.on('SIGINT', () => {
  console.log('\nReceived SIGINT. Shutting down gracefully...');
  server.close(() => {
    console.log('Server closed.');
    process.exit(0);
  });

  // Force exit after timeout
  setTimeout(() => {
    console.log('Forced exit after timeout');
    process.exit(130);
  }, 5000);
});

Handle in Python

import signal
import sys

def signal_handler(sig, frame):
    print('\nInterrupted! Cleaning up...')
    # Perform cleanup
    sys.exit(130)

signal.signal(signal.SIGINT, signal_handler)

# Or use try/except
try:
    while True:
        do_work()
except KeyboardInterrupt:
    print('\nStopped by user')
    sys.exit(130)

Ignore Ctrl+C when needed

#!/bin/bash
# Prevent interruption during critical section
trap '' SIGINT  # Ignore SIGINT

# Critical operation that should not be interrupted
update_database

trap - SIGINT  # Restore default SIGINT handling

# Non-critical section — Ctrl+C works again
wait_for_input

Check for SIGINT in CI/CD

# In scripts, check if a previous command was interrupted
command_that_runs_long
status=$?

if [ $status -eq 130 ]; then
  echo "Process was interrupted by user"
  exit 130
fi