c - 我想让我的 c 程序调度具有特定 CPU 使用率的其他程序
问题描述
我的程序现在只执行其他 c 程序。但我希望这个进程占用 CPU 的(输入值)%。到目前为止,新进程(分叉进程)只占用 CPU 的 0%..有时 0.1%.I希望它采用输入的% ex..25%
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
printf("u_interval=%d\n", u_interval);
for (size_t i = 0; i < schedulees_count; ++i) {
schedulee_t *schedulee = schedulees[i];
printf("schedulee %zu: %d%%\n argv: [", i, schedulee->proportion);
for (size_t j = 0; schedulee->argv[j] != NULL; ++j) {
printf("\"%s\", ", schedulee->argv[j]);
}
printf("\b\b]\n");
int pid = fork(); //The parent(>0) and child(0) is formed
if (pid == 0) {
printf("Hello from Child!\n");
execv(schedulee->argv[0], schedulee->argv);
}
// parent process because return value non-zero.
else{
wait(NULL);
printf("Hello from Parent!\n");
schedulee->pid = pid;
kill(pid,SIGSTOP);
}
}
这是程序的一部分,它通过 execv 命令执行其他程序(任务)。但是新进程只占用 0.0% 的 CPU。例如,我希望它有 25% 的 CPU 使用率。
解决方案
推荐阅读
- php - php pow 函数不适用于 laravel 5.6
- javascript - TypeError: Constructor Set requires 'new'
- sql - 如何从 Oracle SQL Developer 中提取 XML 数据
- ios - ios有什么方法可以在不对对象进行分类的情况下进行对象检测?
- dji-sdk - 为什么雷达小部件在 Mavic_2 中不起作用?
- powershell - 过滤 Get-WmiObject 类属性输出以仅包含值
- http - 在flutter http请求中为所有请求设置默认标头的最佳方法
- php - 如何修复 Codeigniter 中未找到请求的 URL 错误
- arm - USB CDC 通信设备等待来自主机的第二个命令以发送对第一个命令的响应
- python - 根据熊猫中另一列中的值添加列的值