You are not logged in.
Good day!
I have this small script to be called whenever I need waybar to be reloaded:
#!/bin/sh
if
pgrep waybar >/dev/null 2>&1
then
killall -SIGUSR2 waybar &
else
exit 0
fi
The script is working fine, but pgrep keeps reporting
waybar: no process found
instead of shutting up...
These are the usual exit stati according to man pgrep:
EXIT STATUS
0 One or more processes matched the criteria. For pkill and pwait, one or more processes must also have been
successfully signalled or waited for.
1 No processes matched or none of them could be signalled.
I've tried
1>/dev/null
as well to no avail
Am I not seeing the wood for the trees?
Any help is appreciated,
thanks
Last edited by dogknowsnx (2022-04-03 11:49:13)
Offline
The error is coming from killall, not pgrep.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
The error is coming from killall, not pgrep.
The wood for the trees...
Thanks @WorMzy
EDIT: *thinking out loud* I'm still wondering why killall gets executed, if no waybar process is found...
Last edited by dogknowsnx (2022-04-03 13:36:29)
Offline
EDIT: *thinking out loud* I'm still wondering why killall gets executed, if no waybar process is found...
It's called a race condition.
Probably the process was running when pgrep was called, but terminated before killall was called.
Last edited by schard (2022-04-03 13:50:33)
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
It's called a race condition.
Probably the process was running when pgrep was called, but terminated before killall was called.
Thanks for your reply. The thing is that killall gets executed 100% of the time, even outside a graphical environment (where the script gets called from a pacman hook)...
EDIT: Maybe you're onto something though - could it be that killall is seeing 'pgrep waybar' and interprets just 'waybar'?
Will add a 'sleep 1' to the script and see what gives...
Last edited by dogknowsnx (2022-04-03 14:07:18)
Offline
Offline
I have this small script ...
And what is the name of that script? I'd wager it includes "waybar" somewhere it it's name, right? You should use the -x flag for pgrep.
However, do you even really need to test if waybar is running? Just send SIGUSR1 and be done with it. If waybar is running, it will receive the signal, if it isn't, it wont. So the whole script could just be:
killall -SIGUSR2 waybar 2>/dev/null ||:
Last edited by Trilby (2022-04-03 14:59:31)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
dogknowsnx wrote:I have this small script ...
And what is the name of that script? I'd wager it includes "waybar" somewhere it it's name, right? You should use the -x flag for pgrep.
However, do you even really need to test if waybar is running? Just send SIGUSR1 and be done with it. If waybar is running, it will receive the signal, if it isn't, it wont. So the whole script could just be:
killall -SIGUSR2 waybar 2>/dev/null ||:
You nailed it again. I haven't read your comment though when it dawned on me. I was thinking about using the oneliner as well, but figured to play "killall" safe, I guess Thanks everyone - gotta love this forum!
Luckily I'm not a cardiac surgeon...
Last edited by dogknowsnx (2022-04-03 15:09:16)
Offline
Luckily I'm not a cardiac surgeon...
You wouldn't have the heart for it?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
dogknowsnx wrote:Luckily I'm not a cardiac surgeon...
You wouldn't have the heart for it?
That's a good one
Offline