![]() ![]() With awk, we can extract information from a string. The output is essentially the same as the first line of the top command which you can see in the screenshot above. I am using the uptime tool here, which gives us information about the average load over a period of one, five, and 15 minutes. Perhaps you only want to limit the CPU usage of gzip if there is too much load on your server: #!/bin/bash Two gzip processes are running where one has been throttled using cpulimit The $! variable refers to the process ID of the most recently executed background command. Instead of the -e parameter, I've been using -p, which allows you to pass the process ID of the process that you want to throttle. A solution to both issues is this: tar -c myData | gzip -c > myData.gz & However, this solution doesn't solve the first problem. If you wait for three seconds or so, gzip most likely will be running. One way to solve the second problem is to add the sleep command after the first line. In that case, cpulimit will exit with the message "No process found." ![]() Second, on a busy server, cpulimit might start before gzip appears on the process list. ![]() cpulimit might then catch the wrong process. First, you can't be entirely sure that no other gzip process is running. In our case, cpulimit can only use 10% of the available CPU resources. The -e parameter tells cpulimit to search for a process named gzip, and -l specifies the percentage of CPU allowed. Most examples on the web will look more or less like this: tar -c myData | gzip -c > myData.gz &īecause tar does not use much CPU power, we only need to throttle gzip. ![]() On Ubuntu, you just run the following commands: apt update The installation of cpulimit is pretty simple. You will notice that gzip is a real resource hog and will quickly seize all available CPU resources. Let's say you create your backups with tar and compress them with gzip. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |