How can Bash script kill "sleeping" version of itself already running? - Ask Ubuntu


edit comments below wrote confusing/misleading introduction i'm rewriting it.

i have bash script called "lock screen timer" can clicked on desktop. after 30 minutes locks screen , user has enter password unlock screen. if user changes mind, or want reset timer, should able click desktop shortcut again , should kill previouly running job sleeping , counting down.

i've done little trial , error far , hit road-block.

the relevant code snippet is:

pgrep tv-timer > ~/tv-timer.log pid=$$ # current process id 

using cat ~/tv-timer.log:

16382 20711 

one of these equal "$pid" above other running copy want use kill #####.

what's best way of figuring out 1 <> "$pid" , killing it?

the first time script run there 1 entry equal "$pid" don't want kill.

thanks help!


the proposed duplicate (prevent duplicate script run @ sametime) problem within parent , child processes. accepted answers long , complicated involving wrapper scripts and/or multiple lines of code.

the solution sought here one line of new code!

indeed accepted-elect answer here based on duplicate op attempt that not work there!

please, change line:

pgrep tv-timer | grep -v $$ > ~/tv-timer2.log 

into this:

pgrep tv-timer | grep -v ^$$$ > ~/tv-timer2.log 

in fact, if 1 tv-timer prosesses has, say, pid=26019 , should $$ 6019, grep yield empty string, not want.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User