0

This may be a bit weird since I'm going backwards (instead of speeding up a program) but there's a reason for this.

Currently, I have used a file watcher called inotifywait that watches the file changes of a running program. Let's say I have this python program:

import os
os.mkdir('abc')
os.mkdir('abc/def')
os.mkdir('abc/def/ghi')

Since the program is too fast, the file watcher cannot catch up with the file events from the program. Furthermore, to test my theory that if I slow down the program, I added loops between each mkdir(). And now, the file watcher can catch up.

import os
os.mkdir('abc')
for i in range(100000):
  pass
os.mkdir('abc/def')
for i in range(100000):
  pass
os.mkdir('abc/def/ghi')

So, is there a way to deliberately slow down a program or a process in Linux?

Limitations: The program being watched is not modifiable. The example above is just to prove that the file watcher can catch up with the file events if the program is being slowed down.

  • Does this answer your question? [How do I get my program to sleep for 50 milliseconds?](https://stackoverflow.com/questions/377454/how-do-i-get-my-program-to-sleep-for-50-milliseconds) – Karl Knechtel Jan 06 '23 at 06:08
  • 2
    The problem with your loops is that they will consume 100% of the CPU, making it unavailable for other work. `time.sleep` is what you need. – Tim Roberts Jan 06 '23 at 06:12
  • Unfortunately, the program being watched is out of my control. Meaning, I can't modify it. So is there a way to make the program slow without modifying the program. (let me edit my question and put this, my bad) – Cymmer Maranga Jan 06 '23 at 07:03

0 Answers0