User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Bash script help. Thanks!

Sat Dec 19, 2015 5:36 pm

Is there a way to tell if a program has been running for x amount of time for example 1 minute and if it has been running that long kill it.
For example I play a livestream with omxplayer and i want to stop it in a specific time frame.
:twisted:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
rpdom
Posts: 15194
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Bash script help. Thanks!

Sat Dec 19, 2015 6:47 pm

expandables wrote:Is there a way to tell if a program has been running for x amount of time
Yes.

User avatar
rpdom
Posts: 15194
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Bash script help. Thanks!

Sat Dec 19, 2015 6:49 pm

You can use ps if you know the PID of the process

Code: Select all

rpdom@oz:~$ ps -o etime= -p 10962
      06:31

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Bash script help. Thanks!

Sat Dec 19, 2015 6:53 pm

rpdom wrote:You can use ps if you know the PID of the process

Code: Select all

rpdom@oz:~$ ps -o etime= -p 10962
      06:31
Yea thanks i know about that but is there a way to write a script that will always be able to find the pid of the running program and kill it at a specific time.
:twisted:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
rpdom
Posts: 15194
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Bash script help. Thanks!

Sat Dec 19, 2015 7:07 pm

pidof?

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Bash script help. Thanks!

Sat Dec 19, 2015 7:27 pm

rpdom wrote:pidof?
Lets say the pidof of vlc
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

drgeoff
Posts: 9805
Joined: Wed Jan 25, 2012 6:39 pm

Re: Bash script help. Thanks!

Sat Dec 19, 2015 7:30 pm

Code: Select all

man pidof

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Bash script help. Thanks!

Sat Dec 19, 2015 7:56 pm

expandables wrote:Is there a way to tell if a program has been running for x amount of time for example 1 minute and if it has been running that long kill it.
For example I play a livestream with omxplayer and i want to stop it in a specific time frame.
:twisted:
What if you want it to stop at a certain time? You'll need your program to deal with delays and with specific times. It will have to find the right copy of omxplayer (or whatever) and kill that. If you run a program you wrote that then starts omxplayer (or whatever), you can back off things and interact with your own interface. This means you will be able to run the same code to start and stop any player.

Return to “Beginners”