任何替代方法或方法可以使这个脚本更快?

时间:2013-08-31 05:11:28

标签: linux shell scripting

我有这个脚本显示正在使用的终端类型。因此,例如,如果您正在运行konsole,它将显示konsole。该脚本需要进入另一个程序,该程序在打开终端时运行,因此它必须非常快。这是我到目前为止所拥有的

#!/bin/bash
shopt -s extglob
SHELLTTY=$(exec ps -p "$$" -o tty=)
P=$$
while read P < <(exec ps -p "$P" -o ppid=) && [[ $P == +([[:digit:]]) ]]; do
    if read T < <(exec ps -p "$P" -o tty=) && [[ $T != "$SHELLTTY" ]]; then
        ps -p "$P" -o comm=
        break
    fi
done

当脚本保存到文件中时,运行它需要很长时间。

[~]$ time ./termgrab
konsole

real    0m0.063s
user    0m0.017s
sys     0m0.040s

整个程序本身需要0.04秒,所以这会大大减慢它。有没有人有任何建议使脚本更快或任何其他方法来实现相同的东西?

0 个答案:

没有答案
相关问题