Software⏱️ 3 min read📅 2026-06-19

How to Fix: How can I fix a problem with standard error screwing up the output of watch?

Understanding the issue with standard error and its impact on output.

Quick Answer: The problem occurs due to the buffering behavior of the watch command. To fix this, use the "-d" option with jmap to disable buffering.

The issue described is related to the standard error output of the `watch` command being affected by the `jmap -heap` command. This affects users running CentOS and Fedora 14, who are trying to monitor the heap dump of a specific process ID.

This problem can be frustrating for system administrators and developers who need to troubleshoot and analyze the heap dump of a process. In this guide, we will explore the root causes of this issue and provide two primary fix methods to resolve it.

🔍 Why This Happens

  • The first main reason why this error happens is due to the way `watch` processes its output. When using the `2> /dev/null` redirection, the standard error output is discarded, which can cause issues with the output of subsequent commands, including `jmap -heap`. This is because the `watch` command relies on the standard error output to display the process's status and output.
  • An alternative reason for this issue could be related to the specific version of the `jmap` tool being used. In some cases, older versions of `jmap` may not handle the redirection properly, leading to issues with the output.

🔧 Proven Troubleshooting Steps

Using the `2> /dev/null` redirection

  1. Step 1: To fix this issue using the `2> /dev/null` redirection, simply run the command without the redirection: `watch sudo jmap -heap 31945`. This will allow the standard error output to be displayed properly.
  2. Step 2: Alternatively, you can use a pipe to redirect the standard error output to a file instead of discarding it: `watch sudo jmap -heap 31945 2> output.log`. This will save the standard error output to a log file named `output.log`.

Using a different approach

  1. Step 1: Another way to fix this issue is to use a different command to run `jmap -heap`, such as `jstack` instead of `jmap`. The `jstack` command provides more detailed output and can be used without the redirection: `watch sudo jstack 31945 2> /dev/null`. This will allow you to capture the standard error output properly.
  2. Step 2: Note that using `jstack` may require additional configuration or setup, depending on your specific environment and requirements.

✨ Wrapping Up

In conclusion, the issue with the standard error screwing up the output of `watch` can be resolved by using one of the two primary fix methods described above. By understanding the root causes of this issue and trying different approaches, you should be able to resolve the problem and capture the standard error output properly.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions