Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Find PID of a specific sleep process
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
TomaLars
n00b
n00b


Joined: 30 Jul 2019
Posts: 15

PostPosted: Wed Dec 04, 2019 8:21 pm    Post subject: Find PID of a specific sleep process Reply with quote

Hi people (and general creatures),

I am playing with the default dwm bar and I need a little help.
What I'd like to do, is update its status every 60 seconds and also every time I push the volume buttons on my keyboard.
It's basically what Luke explain in this video from 2:30 to 4:30.

I have the script ~/.dwm/dwmrc that collects the information to display in the bar and than put it to sleep for 60 seconds.
Code:
#!/bin/sh
while true; do
    SEP="|"
    DATE=" $(date "+%a %d %h %Y")"
    TIME=" $(date "+%H:%M:%S")"
    AUDIO=$(amixer get Master | grep -o "\[[a-z]\+]" | sed "s/\[on\]//;s/\[off\]//")
    VOLUME=$(amixer get Master | grep -o "[0-9]\+%")

    xsetroot -name "$AUDIO $VOLUME $SEP $DATE $SEP $TIME"
    sleep 60
done

If I change the volume within the 60 seconds and through htop send a signal SIGTRAP to the sleep process that comes from the script above, the bar shows its new status...everything works fine.
But this is just a test...

Now the question:
How can I automatically find the PID of that same sleep process from the command line?
The solution from Luke doesn't work for me.
Keep in mind that I could have more sleep processes at the same time but only one comes from dwmrc.
Back to top
View user's profile Send private message
Muso
Veteran
Veteran


Joined: 22 Oct 2002
Posts: 1002
Location: The Holy city of Honolulu

PostPosted: Wed Dec 04, 2019 9:20 pm    Post subject: Reply with quote

Code:
top

_________________
"You can lead a horticulture but you can't make her think" ~ Dorothy Parker
"It's not a big truck. It's a series of tubes." ~ Senator Ted Stevens describing the Internet
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 18157

PostPosted: Thu Dec 05, 2019 3:13 am    Post subject: Re: Find PID of a specific sleep process Reply with quote

TomaLars wrote:
Now the question:
How can I automatically find the PID of that same sleep process from the command line?
The solution from Luke doesn't work for me.
Keep in mind that I could have more sleep processes at the same time but only one comes from dwmrc.
No idea what Luke's solution is, but in your above script, use echo $$ to save the PID of the script (perhaps to /var/run/myscript.pid). Then use pgrep sleep -P <pid from /var/run/myscript.pid>. That should get you the sleep associated with the script. If your script uses more than one sleep, then that probably won't work. If you do that, be sure to check for and clean up the /var/run/myscript.pid file (when the script starts so it doesn't start again if already running, and clean it up in case of a crash).
_________________
Those who know what's best for us must rise and save us from ourselves.
Back to top
View user's profile Send private message
TomaLars
n00b
n00b


Joined: 30 Jul 2019
Posts: 15

PostPosted: Thu Dec 05, 2019 8:38 pm    Post subject: Reply with quote

Thanks Muso and pjp.
What I was searching for was something to write into a script and the idea of pjp is exactly what i need.
For my case simple and solid.
Back to top
View user's profile Send private message
Muso
Veteran
Veteran


Joined: 22 Oct 2002
Posts: 1002
Location: The Holy city of Honolulu

PostPosted: Fri Dec 06, 2019 3:25 am    Post subject: Reply with quote

TomaLars wrote:
Thanks Muso and pjp.
What I was searching for was something to write into a script and the idea of pjp is exactly what i need.
For my case simple and solid.


pjp is a known bash sorcerer.
_________________
"You can lead a horticulture but you can't make her think" ~ Dorothy Parker
"It's not a big truck. It's a series of tubes." ~ Senator Ted Stevens describing the Internet
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 18157

PostPosted: Fri Dec 06, 2019 3:53 am    Post subject: Reply with quote

:lol:

Just don't get caught in the fallout zone.
_________________
Those who know what's best for us must rise and save us from ourselves.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum