# Start and stop process

**URL:** <https://www.ruby-forum.com/t/start-and-stop-process/241089>\
**Category:** Ruby\
**Created:** [May 12, 2014, 9:47pm UTC](https://www.ruby-forum.com/t/start-and-stop-process/241089 "2014-05-12T21:47:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [May 12, 2014, 9:47pm UTC](https://www.ruby-forum.com/t/start-and-stop-process/241089/1 "2014-05-12T21:47:27Z")

</div>

Hello,

I wrote a simple script to grab an audio stream and save it into a file.  
I need to run this file 5 days a week, the process should record the  
stream for ~ 2 hours. What is the best way to approach this problem?

I’m thinking of starting the process with a cron job, on a FreeBSD  
server, but then what is the best way to control the process based on  
time?

best regards,

Panagiotis (atmosx) Atmatzidis

email: removed\_email\_address@domain.invalid  
URL: [http://www.convalesco.org](http://www.convalesco.org)  
GnuPG ID: 0x1A7BFEC5  
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5

“As you set out for Ithaca, hope the voyage is a long one, full of  
adventure, full of discovery […]” - C. P. Cavafy

---

<div class="post-metadata">

**Author:** ![atma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@atma](https://www.ruby-forum.com/u/atma)\
**Post date:** [May 13, 2014, 5:01am UTC](https://www.ruby-forum.com/t/start-and-stop-process/241089/2 "2014-05-13T05:01:55Z")

</div>

I remember there is a gem named “whenever”.

Yuanhang Zheng.  
2014-5-13 上午3:47于 “Panagiotis A.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)写道：

---

<div class="post-metadata">

**Author:** ![atma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@atma](https://www.ruby-forum.com/u/atma)\
**Post date:** [May 13, 2014, 5:24am UTC](https://www.ruby-forum.com/t/start-and-stop-process/241089/3 "2014-05-13T05:24:06Z")

</div>

On Mon, May 12, 2014 at 12:46 PM, Panagiotis A.  
\<[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> wrote:

> Hello,
> 
> I wrote a simple script to grab an audio stream and save it into a file. I  
> need to run this file 5 days a week, the process should record the stream  
> for ~ 2 hours. What is the best way to approach this problem?
> 
> I’m thinking of starting the process with a cron job, on a FreeBSD server,  
> but then what is the best way to control the process based on time?

I’m sure there may be fancier ways - but a pid file and another cron  
task 2  
hours later that kills the pid is as simple and as clean as you can get.  
I  
do this exact thing myself and it works like a charm.

John

---

<div class="post-metadata">

**Author:** ![atma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@atma](https://www.ruby-forum.com/u/atma)\
**Post date:** [May 13, 2014, 6:52am UTC](https://www.ruby-forum.com/t/start-and-stop-process/241089/4 "2014-05-13T06:52:36Z")

</div>

Subject: start and stop process  
Date: Mon 12 May 14 09:46:45PM +0200

Quoting Panagiotis A. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):

> I’m thinking of starting the process with a cron job, on a FreeBSD  
> server, but then what is the best way to control the process based  
> on time?

There is a class called Timeout: “provides a way to auto-terminate a  
potentially long-running operation if it hasn’t finished in a fixed  
amount of time.”

Carlo
