高级进程管理与资源限制解析
1. 进程时间片获取
sched_rr_get_interval() 函数用于获取指定进程的时间片长度。成功调用该函数时,会将分配给 pid 的时间片持续时间保存到 tp 所指向的 timespec 结构体中,并返回 0;失败时返回 -1,并设置相应的 errno 。
代码示例
struct timespec tp;
int ret;
/* get the current task's timeslice length */
ret = sched_rr_get_interval (0, &tp);
if (ret == -1) {
perror ("sched_rr_get_interval");
return 1;
}
/* convert the seconds and nanoseconds to milliseconds */
printf ("Our time quantum is %.2lf milliseconds\n",
(tp.tv_sec * 1000.0f) + (tp.tv_nsec / 1000000.0f));
错误代码
| 错误代码 | 描述 |
|---|---|
超级会员免费看
订阅专栏 解锁全文
6464

被折叠的 条评论
为什么被折叠?



