Why is my PID off by one in this Bash script?

0
2
Asked By CraftyFox77 On

I'm working on a Bash script where I need to manage a timer using inotifywait. The script logs show a process ID (PID) that doesn't match the PID I get when I run `ps aux | grep "[s]leep 10"`. It consistently appears to be off by one. I'm not sure what I'm doing wrong. The aim is to reset the timer with each update from inotifywait and then execute a command afterward. Any insights on this issue would be really appreciated!

1 Answer

Answered By CuriousCoder21 On

It looks like the issue arises because you're backgrounding the `trigger_update` function instead of the `sleep` command itself. When you run a command in the background, the PID you capture is for that subshell running the entire function, not just the `sleep`. To fix this, try backgrounding the `sleep` within the function directly. This should give you the correct PID for your timer.

TimerTinkerer42 -

Thanks for the tip! Is there a more effective way to manage timers without creating conflicts or stacking them?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.