Happy New Year, Kris. Isn't your desired behavior the textbook case for flock-ing? i.e. check with flock at the beginning of the script, and abort if it fails?
Well look at that. I had not heard of flock before. But there it is, even on my Android shell. Why didn't that come up when I was looking up information on this. Thank you. I'll have to play around with this and do an updated video.
I suppose that could happen, but pids tend to get larger and a larger number won't be part of a smaller number. But, I believe there are times where Linux might start looping back to smaller numbers. I guess the solution to that is to only return results if there is a full line match. something like this: pgrep -f zsh|grep -Fxv $$
i might use this what i will first think of when i'm given this task: ``` if ! [ "`pgrep "$0"|grep -v "$$"`" = "" ] then printf " ==> ERROR:\"$0\" is being run more than once at the same time
thank you very much Kris, Happy new year. keep going 🤩
Happy new year! Glad you found it helpful.
Thanks Kris. Happy New Year
Happy New Year to you too!
Thanks Kris! Happy New Year!
Same to you!
Happy New Year, Kris. Isn't your desired behavior the textbook case for flock-ing? i.e. check with flock at the beginning of the script, and abort if it fails?
Well look at that. I had not heard of flock before. But there it is, even on my Android shell.
Why didn't that come up when I was looking up information on this. Thank you. I'll have to play around with this and do an updated video.
Happy New Year!
Happy new year!
super helpfull, thank you
Glad it was helpful!
When you are using grep -v, I think there may be a problem where the pid you are grepping out is a substring of one of the other pids.
I suppose that could happen, but pids tend to get larger and a larger number won't be part of a smaller number. But, I believe there are times where Linux might start looping back to smaller numbers. I guess the solution to that is to only return results if there is a full line match. something like this:
pgrep -f zsh|grep -Fxv $$
Nice.
Thanks!
Instead pipe to dev null, is grep -q not work?
Yes, I think that would work. I haven't tried it. I just didn't think of that. Thank you.
i might use this
what i will first think of when i'm given this task:
```
if ! [ "`pgrep "$0"|grep -v "$$"`" = "" ]
then
printf " ==> ERROR:\"$0\" is being run more than once at the same time
"
exit 1
fi
```
but yours is just a nice oneliner
Yeah, basically the same thing, just shortened up a little.