Cymmer Maranga
Cymmer Maranga

Reputation: 1

How to deliberately slow down a program in Linux?

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.

Upvotes: 0

Views: 268

Answers (0)

Related Questions