Clear screen in watch command

I usually run many programs from the same shell before using the watch command to monitor programs for completion. (I'm filtering the ps command a bit, but this example is simpler.)

sleep 10 && for i in {1..100}; do echo $i; done &
watch -n 5 ps aux

The watch command clears the terminal so that the command output is clean and there is no interference.

Watch command output

When another program prints, for example, echo expressions in the example, the result is a bit strange. It prints weirdly, and the results seem to depend on the size of the output. Although the watch must restart the ps aux command, it does not overwrite the output of the echo commands.

After the sn timer is completed

Is there something similar that would prevent other programs from being released to cover the weekend?

watch -n 5 ClearScreenSomehow && ps aux
+4
source share
2

, . - , :

:

#delayed print to clutter up watch later
bash -c 'sleep 10; echo ASDF' &
#watch dummy command, observe cluttering
watch -n1 'ls -la |head -25'

- , , , /dev/null.

gdb. , -batch pid, .

bash -c 'sleep 10; echo ASDF' &
#sudo gdb -p "$!" -batch -ex 'p dup2(open("/dev/null",0),1)' -ex 'p dup2(open("/dev/null",0),2)' -ex 'detach'
gdb -p "$!" -batch -ex 'p dup2(open("/dev/null",0),1)' -ex 'p dup2(open("/dev/null",0),2)' -ex 'detach'
watch -n1 'ls -la |head -25'

$! - pid , . pid, , pid $! .

, gdb sudo , - ( ) sudo. .

+2

, .

- , . , .

screen tmux . xterm , , - .

+1

Source: https://habr.com/ru/post/1618043/


All Articles