請問有關於 top, watch - BBS

Table of Contents

大家都知道 Linux 上有一個 command 叫做 watch

可以週期性的執行 command

現今我想要寫一個 script 來模擬

想法如下

while :; do
clear
待執行的 command
sleep 1
done

可是我發現這樣會有一些問題, 如果是執行比較花時間的 command, ex

ls -al | cat, 螢幕就會閃爍, 沒有辦法像 top, 或是 Linux 上的

watch 一樣順

現在有兩個問題

1. 較花時間的 command 會閃爍是什麼原因呢??

(我猜測是因為上一次執行 command 的輸入還沒印完, 就已經執行 clear

及下一次的 command)

2. 改怎麼處理這種情形呢?? 我 man 了 clear 和 terminfo 沒找到解決方法

希望有人指點我一下

感謝 QQ

--

All Comments