0

I wrote a loop in dash which waits for a file to appear in a certain location on the filesystem. But when it runs it takes up 50% of the CPU. I first lowered the CPU usage using a sleep command but the minimal sleep time in dash (1 second) is too long for me.

I need a way to sleep less than 1 second in bash or a different solution to lower the CPU usage of the loop. I only want to use programs that are installed by default on the most unix systems.

timakro
  • 1,739
  • 1
  • 15
  • 31
  • Instead of busy-waiting for the file to appear, use the file-system monitoring tools appropriate for your operating system (`inotify`, `fswatch`, etc.) – chepner May 26 '15 at 16:28

1 Answers1

0

On my Linux system, I can simply do

$ sleep 0.1

and it sleeps for 0.1 seconds. The sleep here lives in /usr/bin/sleep. I don't know which other unix-like systems support that, though.

cfh
  • 4,576
  • 1
  • 24
  • 34