背景:服务器上有大量数据和文件,我需要打包并下载到本地,打包时通过top命令发现zip命令对应的进程会占满cpu使用率,为了避免影响其他用户的使用,我需要限制打包进程及其子进程的cpu使用率
# 下载和安装cpulimit
wget -O cpulimit.zip https://github.com/opsengine/cpulimit/archive/master.zip
unzip cpulimit.zip
cd cpulimit-master
make
sudo cp src/cpulimit /usr/bin
参考https://blog.csdn.net/chengouza3763/article/details/100834559
# 使用管道打包多个文件
find $work -type f -name "*.dat" | xargs cp {} data/
# 查看cpulimit使用方法
cpulimit -h
# 限制cpu使用率为60%
cpulimit -i -l 60 tar zcvf data.tgz data