Preventing Deep Learning Training Processes from Getting Killed on Ubuntu 20.04

Abstract: Resolve unexpected deep learning training process terminations on Ubuntu 20.04 by configuring swap space and adjusting kernel memory parameters to prevent OOM kills.

Created: 2026-09-24 by
Training jobs for deep learning models often terminate unexpectedly on Ubuntu 20.04 due to system resource limits, particularly when CPU usage spikes during data loading or model compilation. This behavior is typically caused by the Out-Of-Memory killer or aggressive process management policies that prioritize system stability over long-running computational tasks. By adjusting kernel parameters and managing user processes correctly, you can ensure your training scripts run to completion without interruption.

Understanding Process Termination Causes

When a deep learning process is killed, it is usually because the operating system has determined the process is consuming too many resources or violating specific security policies. The most common culprits are the Linux Out-Of-Memory (OOM) killer and the systemd service manager. Understanding which component is terminating your job is the first step toward a permanent fix.

The OOM killer activates when the system runs out of physical RAM and swap space. In deep learning scenarios, even if you are using a GPU, the CPU must handle data preprocessing, augmentation, and batch loading. If these operations consume excessive memory, the kernel may sacrifice the training process to keep the OS responsive. Similarly, systemd might kill processes that exceed their allocated time or resource limits, especially if they are run as background services rather than interactive sessions.

Checking System Logs

To identify the exact cause, you should examine the system logs immediately after a termination. Use the dmesg command to view recent kernel messages. Look for lines containing "Out of memory" or "oom_kill". If you see these entries, the issue is definitively related to memory exhaustion. Alternatively, check the journalctl logs for systemd-related terminations:

dmesg | grep -i oom
journalctl -xe | grep -i killed

If the logs indicate an OOM event, you need to increase available memory or optimize your data pipeline. If no OOM message appears, the process might be terminated by a timeout policy or manual intervention from another admin. In such cases, checking the process ownership and session type is crucial.

Optimizing Memory Management

One effective way to prevent kills due to memory pressure is to adjust the virtual memory settings. Ubuntu uses a swappiness value to determine how aggressively it swaps data from RAM to disk. While high swappiness can slow down performance, it can also prevent immediate OOM kills by providing more buffer space. You can view the current setting with:

cat /proc/sys/vm/swappiness

For training workloads, a slightly higher swappiness value might help, but this depends heavily on having sufficient disk I/O bandwidth. More importantly, ensure you have adequate swap space configured. If your system has 16GB of RAM, consider adding at least 8-16GB of swap file to act as a safety net. This prevents the kernel from killing processes the moment free RAM drops to zero.

Additionally, monitor your actual memory usage during training. Tools like htop or nvidia-smi (for GPU memory) provide real-time insights. If CPU memory usage climbs steadily until the crash, your data loader is likely inefficient. Reducing the number of worker threads in your PyTorch or TensorFlow data loaders can significantly lower memory overhead.

Managing Process Sessions Correctly

Another frequent reason for termination is running training scripts directly in a terminal window. If the SSH connection drops or the terminal closes, the SIGHUP signal is sent to all child processes, causing them to exit. To prevent this, use terminal multiplexers like tmux or screen. These tools detach the process from the terminal session, allowing it to continue running even if you disconnect.

tmux new -s training_session
python train.py

By detaching with Ctrl+B D, you can safely close your SSH client. Later, reconnect and reattach with tmux attach -t training_session. This method is reliable and does not require changing system-level configurations. It is the standard practice for long-running experiments on remote servers.

Adjusting Systemd Limits

If you are running your training job as a systemd service, it might be subject to strict resource limits defined in the service unit file. Check the LimitNOFILE and MemoryMax directives. Default values might be too low for large-scale data processing. Edit the service file located in /etc/systemd/system/ or /lib/systemd/system/ to increase these limits. For example:

[Service]
LimitNOFILE=65536
MemoryMax=8G

After modifying the configuration, reload the daemon with systemctl daemon-reload and restart the service. This ensures that the process is allowed to open more files and consume more memory before being terminated. Note that increasing limits requires root privileges, so ensure you have appropriate access rights.

Related Resources

If you encounter storage issues while saving large checkpoints, you might need to manage your partition sizes effectively. See Increasing the Size of Home Partition in Ubuntu 23.04 for guidance on expanding storage capacity. Additionally, if your server relies on network connectivity for dataset retrieval, ensure your VM networking is stable. Refer to Ubuntu 22.04 VM on KVM/virt-manager Not Connecting to Internet to troubleshoot connection drops that could interrupt data streaming.

Frequently Asked Questions

How do I know if my process was killed by OOM?

Check the kernel ring buffer using dmesg | grep -i oom. If you see messages indicating memory allocation failure and process termination, the OOM killer was responsible. This confirms that your system ran out of usable RAM and swap space.

Can I disable the OOM killer completely?

No, disabling the OOM killer is dangerous as it can freeze the entire system if memory is exhausted. Instead, optimize your application's memory usage or increase available swap space to provide a safer buffer against crashes.

Why does my training stop when I close the terminal?

Closing the terminal sends a hangup signal (SIGHUP) to all child processes. Using tmux or nohup detaches the process from the terminal session, preventing it from receiving this signal upon disconnection.

Is increasing swap space enough to prevent kills?

Increasing swap space helps avoid immediate OOM kills by providing additional virtual memory. However, if your disk I/O is slow, heavy swapping will drastically reduce training speed. It is a trade-off between stability and performance.

How do I check systemd resource limits for a service?

Use the command systemctl show --property=LimitNOFILE,MemoryMax to view current limits. If the values are low, edit the corresponding .service file in /etc/systemd/system/ to raise them and reload the daemon.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More