In a code review on Final look at my Lightshot print screen Linux handler POSIX shell script, specifically in this short answer, it has been pointed out to me, that if there are multiple X servers served (simply put, a real multi-user environment), my simple test for PID of a Lightshot.exe executable with pgrep -o Lightshot.exe could be wrong, however slight chance of this I can see happening...
I now came up with the following:
#-o, --oldest: least recently started
#-u, --euid : match by effective UID
pgrep Lightshot.exe -o -u "$( id -u )"
Am I on the right track? If not, can you help me with better approach?
scrot? Simple and powerful for scripting! I use them for creating animated gifs, withnetpbmandgifsiclelike tthis: Progress Parallel Grep and How to add progressbar in bashobs-studio!pgrepprtoblem, As POSIX environment should hold a$UIDvariable, you could try:pgrep -u $UID Lightshot.exeorps U $UID ho pid,comm | sed -ne 's/ Lightshot.exe//p'