How to change time format to seconds in ps -p?
You can try something like:
time=$(ps -p $processid -o etime= | tr -d ' ');
time_in_seconds=$(case ${#time} in "8") echo ${time: -2}+${time: -5:2}*60+${time: -8:2}*3600 | bc;; "5") echo ${time: -2}+${time: -5:2}*60 | bc;; *) echo $(echo $time | cut -d'-' -f1)*86400+${time: -2}+${time: -5:2}*60+${time: -8:2}*3600 | bc;; esac)
echo $time_in_seconds
Newer versions have etimes option which returns time in seconds.