当前位置: 首页 > wzjs >正文

做微信公众号页面的网站沈阳百度seo排名优化软件

做微信公众号页面的网站,沈阳百度seo排名优化软件,wordpress 3.6漏洞,张家口网站建设费用1. Linux 进程中的 nice 值 nice 值通过调整进程的优先级,间接控制 CPU 时间片的分配权重,从而实现对进程调度行为的精细控制。它是 Linux 系统中平衡实时任务与后台任务资源占用的核心工具之一。 优先级调整 核心机制:nice 值(…

1. Linux 进程中的 nice 值

nice 值通过调整进程的优先级,间接控制 CPU 时间片的分配权重,从而实现对进程调度行为的精细控制。它是 Linux 系统中平衡实时任务与后台任务资源占用的核心工具之一。

优先级调整
核心机制:nice 值(范围 -20 到 19)直接控制进程的调度优先级。
低 nice 值(如 -20):表示高优先级,进程更容易被调度器选中,获得更多 CPU 时间片。
高 nice 值(如 19):表示低优先级,进程被调度的频率降低,CPU 时间片分配减少。

记忆:一个进程的 nice 值越高,说明对别的进程越 nice,别的进程运行得越好越快。

2. 代码

设计说明

  • 独立程序:高优先级和低优先级程序完全分离,便于独立运行和调试。
  • CPU 绑定:两个程序均绑定到 CPU 0,消除多核干扰。
  • 时间片观测:每秒打印计数器增量,反映时间片分配比例。

a. high_nice.cc

#include <iostream>
#include <unistd.h>
#include <sys/resource.h>
#include <sched.h>
#include <atomic>
#include <thread>// 绑定到指定 CPU 核
void bind_cpu(int cpu_id) {cpu_set_t mask;CPU_ZERO(&mask);CPU_SET(cpu_id, &mask);if (sched_setaffinity(0, sizeof(mask), &mask) < 0) {perror("sched_setaffinity");exit(1);}
}// 设置进程的 nice 值
void set_nice(int niceness) {if (setpriority(PRIO_PROCESS, 0, niceness) < 0) {perror("setpriority");exit(1);}
}std::atomic<long> counter(0);  // 全局计数器void worker() {while (true) {counter++;  // 高速递增计数器}
}void reporter() {long last = 0;while (true) {std::this_thread::sleep_for(std::chrono::seconds(1));long current = counter.load();std::cout << "[HIGH] Increment: " << current - last << std::endl;last = current;}
}int main() {bind_cpu(0);         // 绑定到 CPU 0set_nice(-5);       // 设置最高优先级(需 root 权限)std::thread t1(worker);std::thread t2(reporter);t1.join();t2.join();return 0;
}

b. low_nice.cc

#include <iostream>
#include <unistd.h>
#include <sys/resource.h>
#include <sched.h>
#include <atomic>
#include <thread>// 绑定到指定 CPU 核
void bind_cpu(int cpu_id) {cpu_set_t mask;CPU_ZERO(&mask);CPU_SET(cpu_id, &mask);if (sched_setaffinity(0, sizeof(mask), &mask) < 0) {perror("sched_setaffinity");exit(1);}
}// 设置进程的 nice 值
void set_nice(int niceness) {if (setpriority(PRIO_PROCESS, 0, niceness) < 0) {perror("setpriority");exit(1);}
}std::atomic<long> counter(0);  // 全局计数器void worker() {while (true) {counter++;  // 高速递增计数器}
}void reporter() {long last = 0;while (true) {std::this_thread::sleep_for(std::chrono::seconds(1));long current = counter.load();std::cout << "[LOW]  Increment: " << current - last << std::endl;last = current;}
}int main() {bind_cpu(0);         // 绑定到 CPU 0set_nice(10);        // 设置最低优先级std::thread t1(worker);std::thread t2(reporter);t1.join();t2.join();return 0;
}

c. Makefile

CPP = g++
CFLAGS = -std=c++11 -pthread -O2
TARGETS = high_nice low_niceall: $(TARGETS)high_nice: high_nice.cc$(CPP) $(CFLAGS) $< -o $@low_nice: low_nice.cc$(CPP) $(CFLAGS) $< -o $@clean:rm -f $(TARGETS)

运行:

make# bash1
sudo ./high_nice# bash2
sudo ./low_nice

3. 结果测试

nice 值为 -5 的占据 CPU 的 96%, nice 值为10 的占据 CPU 的3.7%。

在这里插入图片描述

http://www.dtcms.com/wzjs/525870.html

相关文章:

  • 针织东莞网站建设技术支持关键词优化师
  • 幼儿园网站建设发展规划网站排名查询站长之家
  • WordPress文章无图不展示重庆seo推广运营
  • 建设一个网站的操作流程300字营销策划思路
  • 番禺网站开发报价优化关键词排名外包
  • 外贸网站建设需求免费seo网站优化工具
  • 怎么用ai做网站版面营销策略4p分析怎么写
  • 学校网站建设 应用情况seo优化实训报告
  • 网站推广策划方案毕业设计广告投放怎么做
  • 西安学校网站建设费用沈阳网站关键词排名
  • 小型公司网站建设论文太原网络营销公司
  • 制作网页的视频教程seo常用工具包括
  • 互联网网站建设哪家好线上营销推广
  • 创建公司网站免费网络营销知识
  • 做推文封面的网站谷歌浏览器下载手机版app
  • 平面设计招聘唐山家庭优化大师下载
  • 高质量网站内容建设标准发布广告的平台免费
  • 吉林省建设工程监理检测网站国外搜索网站排名
  • 郑州网站建设丶汉狮网络武汉网络推广平台
  • 如何制作外贸网站百度在线咨询
  • 网站建设公司盈利搜索引擎地址
  • css做的简单网站如何注册域名及网站
  • 软件技术论文题目百度关键词优化专家
  • 宣传文案模板杭州seo排名优化
  • 沧州最火网站seo研究中心教程
  • 南阳高质量建设大城市网站网站搜索优化技巧
  • 怎么用花生壳做网站seo基础理论
  • wordpress4.6教程seo线上培训多少钱
  • 常州网站建设设计百度seo关键词优化公司
  • 禹城网站建设费用新航道培训机构怎么样