135
BashCRITICALSignalHIGH confidence

Bus error (SIGBUS)

Production Risk

Common with mmap() and concurrent file operations; always unmap before truncating.

What this means

Exit code 135 (128+7) indicates a SIGBUS — a bus error. Unlike SIGSEGV (which is a permissions violation), SIGBUS usually means a memory alignment error or that a memory-mapped file was truncated while in use.

Why it happens
  1. 1Accessing a memory-mapped file that was truncated (the page no longer exists)
  2. 2Unaligned memory access on architectures that require alignment (ARM, SPARC)
  3. 3Accessing memory beyond the end of a memory-mapped region
How to reproduce

Accessing a memory-mapped file after it was truncated.

trigger — this will error
trigger — this will error
#!/bin/bash
cat > bustest.c << 'EOF'
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
int main() {
    int fd = open("/tmp/testfile", O_RDWR|O_CREAT|O_TRUNC, 0600);
    ftruncate(fd, 4096);
    char *p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    ftruncate(fd, 0);  // Shrink file while mapped
    p[0] = 'x';       // SIGBUS — page no longer exists
    return 0;
}
EOF
gcc -o bustest bustest.c && ./bustest
echo "Exit: $?"

expected output

Bus error (core dumped)
Exit: 135

Fix

Never truncate a file while it is memory-mapped

WHEN Working with mmap()

Never truncate a file while it is memory-mapped
// munmap before truncating
munmap(p, size);
ftruncate(fd, new_size);
// Then remap if needed
p = mmap(NULL, new_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

Why this works

Unmapping before truncation ensures no process accesses pages that no longer exist in the file.

Sources
Official documentation ↗

GNU Bash Manual — Signals

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Bash errors