D
D
DiGiTAll2019-06-17 15:13:23
Debian
DiGiTAll, 2019-06-17 15:13:23

How to run console command twice per second?

You need to run one console command every 500ms. What is the best way to do this? (Debian 9)
Daemons? System services?
Please help with an example or a link.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ronald McDonald, 2019-06-17
@Zoominger

Throw in Cron:
This is one of the options.

I
Ivan, 2019-06-17
@IvanTheCrazy

Well then, like this:
and your anotherscript will look like

#!/bin/bash
for i in {1..120}
do
  yourcommand
  sleep 0.5
done

I.e.:
- cron will run the script once per minute
- the script will run your application 120 times in this minute, i.e. twice per
second

L
Lander, 2019-06-17
@usdglander

With such a frequency, it is better to write a script with an infinite loop inside and count 500 ms in it.

while (true) {
    //Тут пишутся действия, которые необходимо выполнить

    usleep(500);
}

Just be careful with your memory. It's very easy to catch a memory leak in php. In general, it is not very well adapted for such tasks, but since it is indicated in the tags ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question