omics.co.in logo omics.co.in

9: Process Management, Multi-Core Processing & GNU Parallel

Tested Stacks: GATK 4.6.1 Samtools 1.21 Nextflow 24.10 Seurat v5.1 Python 3.12
Prerequisites: Basic Linux CLI & Sequencing Formats
📚 Chapter 9 of 13 0% Course Completed

Chapter 9: Process Management, Multi-Core Processing & GNU Parallel

Genomic analyses are compute- and memory-intensive: aligners saturate 64 CPU cores, and de novo assemblers can consume hundreds of gigabytes of RAM. Managing system resources, keeping long-running pipelines active across network disconnections, and parallelizing repetitive sample processing across all available CPU threads are critical competencies for any bioinformatician.

The Terminal Disconnection Nightmare

If you launch a 10-hour alignment job over a standard SSH session and close your laptop, your SSH session terminates. The Linux kernel sends a SIGHUP (Hangup) signal to all child processes, immediately terminating your pipeline. Terminal multiplexers like tmux decouple your processes from your physical network connection, ensuring jobs run uninterrupted.

1. Inspecting Running Processes & RAM

# Interactive real-time process monitoring (CPU and memory consumption)
top
htop  # Enhanced visual process monitor (install via conda/apt)

# Check available system RAM in human-readable gigabytes
free -h

# Check available hard drive disk space on all mounted filesystems
df -h

# Find specific running processes matching 'bwa'
ps aux | grep bwa

2. Background Execution & Job Control

# Append an ampersand (&) to launch a process directly into the background:
fastqc sample.fastq.gz &

# Job control shortcuts:
Ctrl + C   # Terminate (interrupt) current foreground process
Ctrl + Z   # Pause (suspend) current foreground process

# View all active background jobs in the current shell session:
jobs -l

# Resume a suspended job in the background:
bg %1

# Bring a background job back into the foreground:
fg %1

3. Persistent Sessions with tmux

tmux (Terminal Multiplexer) creates persistent sessions that survive network drops, computer sleep, and SSH timeouts:

# Start a new named tmux session
tmux new -s rnaseq_run

# Inside tmux: Launch your pipeline normally
./run_full_rnaseq_cohort.sh

# Detach from the session safely: Press Ctrl+b, then release and press d
# Your pipeline continues running in the background on the server!

# Later (from any computer): Re-attach to your running session
tmux attach -t rnaseq_run

# List all active tmux sessions on the machine
tmux ls

4. Terminating Unresponsive Processes

# Send a graceful termination signal (SIGTERM 15) by Process ID (PID)
kill 12345

# Send a forceful, unignorable kill signal (SIGKILL 9) if the process is hanging
kill -9 12345

# Terminate all processes matching a specific tool name
killall bwa-mem2
pkill -u $USER samtools

5. High-Throughput Scaling with GNU Parallel

Instead of processing samples sequentially in a slow for loop, GNU Parallel distributes tasks across all CPU cores simultaneously:

# Run FastQC on all FASTQ files using 16 concurrent CPU jobs:
parallel -j 16 "fastqc {} -o qc_reports/" ::: *.fastq.gz

# Parallelize paired-end read alignment across multiple samples:
# Given a list of sample names in samples.txt:
parallel -j 4 --colsep ' ' \
    "bwa-mem2 mem -t 8 /ref/GRCh38.fa {1}_R1.fq.gz {1}_R2.fq.gz | samtools sort -o {1}.bam -" \
    :::: samples.txt
⚠️

Common Pitfalls & Troubleshooting Checklist

  • Java Heap Exhaustion (GATK / Picard): If processes terminate with java.lang.OutOfMemoryError, set your environment variable explicitly: export _JAVA_OPTIONS="-Xmx16g -Djava.io.tmpdir=/tmp".
  • Index Timestamp Mismatch: If tools complain that a BAM index is missing or out of date, regenerate with samtools index -@ 4 sample.bam.
  • Conda Channel Conflicts: Avoid ABI incompatibilities between bioconda and conda-forge by setting strict priority: conda config --set channel_priority strict.
  • Chromosome Naming Contamination: Always verify whether reference FASTA headers use chr1 or 1; divergent naming causes silent alignment drops.
Was this guide helpful to your research?
Help us maintain 100% accurate, peer-reviewed bioinformatics standards.
📝 Propose Edit on GitHub ↗