How to Change Wget Logging Behavior via Signals
This article provides a quick overview of how to modify the logging
behavior of a running wget process without restarting it.
When executing long-running downloads in the background, you may need to
redirect output to track progress or quiet down a verbose log. Linux and
Unix-like systems allow you to achieve this dynamically by sending
specific POSIX signals—specifically SIGUSR1 and
SIGINT—directly to the active process.
Modifying Wget Logs with SIGUSR1
The most common scenario involves a wget process that is
currently logging its progress directly to the terminal (stderr). If you
need to log out of your session or clear up your terminal, you can send
the SIGUSR1 signal to background the logging.
- The Effect: When
wgetreceives aSIGUSR1signal, it immediately switches its output writer. It turns off logging to the terminal and redirects all subsequent download progress and status updates to a file namedwget-log. - The Command: To send this signal, you first need to
find the Process ID (PID) of your running
wgetcommand and then use thekillcommand:
kill -USR1 <PID>Note: If a file named
wget-logalready exists in the current working directory,wgetwill automatically append a suffix (e.g.,wget-log.1) to avoid overwriting your previous logs.
Background Changes via SIGINT
While SIGINT (Signal Interrupt) is traditionally
used to terminate a program entirely (equivalent to pressing
Ctrl+C), wget handles this signal with
specific nuance during active downloads.
- The Effect: If you initiate a download and
immediately push it to the background or if the system intercepts
certain interrupt requests,
wgetmay interpret the interrupt as a cue to stop writing to the screen. - The Behavior: Instead of killing the process outright in specific background configurations, it redirects the current output stream to a file, ensuring that the data stream is not lost mid-transfer due to an accidental terminal disconnection.
How to Find the PID and Send Signals
To successfully alter the logging of your running wget
process, follow these quick steps in your terminal:
- Locate the Process ID: Use
pgreporpsto find the exact PID of the download task.
pgrep -l wget- Send the Signal: Use the
killcommand followed by the signal flag and the PID you located in the previous step.
kill -10 <PID> # 10 is the standard numeric value for SIGUSR1 on most Linux architectures- Verify the Output: Check your current directory for the creation of the new log file to ensure the signal was caught successfully.
tail -f wget-log