Reputation: 2019
You read it right: I want to make the "find" command of Linux slower and using less system resources. I created a cronjob that runs the find command once every 10 minutes but when it runs the find command uses almost all my CPU for about 3 minutes, leaving almost nothing left to my SO.
So I would like to be able to make the "find" command run a little slower so it does not use so much resources of my Centos server and run steady in the 10 minutes instead of using all resources for 3 minutes.
Is it possible?
Upvotes: 1
Views: 1337
Reputation: 8412
You can't make it slow down internally unless you can recompile the codes and add some delay function..
here is how can can slow down or delay the find command iteration execution
find -type f -exec sh -c 'echo {};sleep 1' \;
make it sleep every 1 second before printing the file name or (whatever codes you prefer to execute.)
Upvotes: 2
Reputation: 585
According to this:
The nice command tweaks the priority level of a process so that it runs less frequently. This is useful when you need to run a CPU intensive task as a background or batch job. The niceness level ranges from -20 (most favorable scheduling) to 19 (least favorable). Processes on Linux are started with a niceness of 0 by default. The nice command (without any additional parameters) will start a process with a niceness of 10. At that level the scheduler will see it as a lower priority task and give it less CPU resources.
So you can simply wrap your task inside a nice
which will change the priority of the task.
Change
whatever
To
nice whatever
Upvotes: 8