Any alternatives or ways to make this script faster?
I have this script which displays the terminal type being used. So for
instance if you were running konsole it would display konsole. The script
needs to go into another program that runs when a terminal is opened so it
has to be very fast. Here's what I have so far
#!/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
When the script is saved into a file it takes this long for it to run.
[~]$ time ./termgrab
konsole
real 0m0.063s
user 0m0.017s
sys 0m0.040s
The whole program itself takes .04 seconds so this slows it down
considerably. Does anyone have any suggestions to make the script any
faster or any alternative ways to achieve the same thing?
No comments:
Post a Comment