进程的优先级设置与获取,进程时间
2016-09-28 08:32
169 查看
进程的优先级设置与获取:值越小优先级越高
#include <sys/time.h>
#include <sys/resource.h>
int niece(int add)
int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int prio);
which:
PRIO_PROCESS 进程
PRIO_PGRP 进程组
PRIO_USER 用户ID
who: = 0
进程时间:
#include <sys/times.h>
clock_t times(struct tms *buf);
struct tms {
clock_t tms_utime; /* user time */
clock_t tms_stime; /* system time */
clock_t tms_cutime; /* user time of children */
clock_t tms_cstime; /* system time of children */
};
#include <sys/time.h>
#include <sys/resource.h>
int niece(int add)
int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int prio);
which:
PRIO_PROCESS 进程
PRIO_PGRP 进程组
PRIO_USER 用户ID
who: = 0
进程时间:
#include <sys/times.h>
clock_t times(struct tms *buf);
struct tms {
clock_t tms_utime; /* user time */
clock_t tms_stime; /* system time */
clock_t tms_cutime; /* user time of children */
clock_t tms_cstime; /* system time of children */
};
#include<sys/resource.h> #include<sys/times.h> void PocessPriorityTest() { pid_t pid_1,pid_2; pid_1 = fork(); if(pid_1 ==0) { cout<<"pid_1 priority = "<<nice(0)<<endl; getpriority(PRIO_PROCESS,0); setpriority(PRIO_PROCESS,0,1); setpriority(PRIO_PROCESS,0,20); cout<<"pid_1 priority = "<<nice(0)<<endl; for(int i=0; i<4; i++) { cout<<"pid_1 "<<endl; sleep(1); } exit(1); } else { pid_2 = fork(); if(pid_2 ==0) { struct tms tmsstart ,tmsend; clock_t start = times(&tmsstart); cout<<"pid_2 priority = "<<nice(0)<<endl; for(int i=0; i<4; i++) { cout<<"pid_2 "<<endl; sleep(1); } clock_t ends = times(&tmsend); cout<<"time = "<<ends-start<<endl; exit(1); } waitpid(pid_1,NULL,0); waitpid(pid_2,NULL,0); cout<<"process end"<<endl; } }
相关文章推荐
- 进程的优先级设置与获取,进程时间
- 进程优先级获取和设置
- C# Timer 控件 c#怎么获取timer剩余时间 倒计时数秒 如何获取 Interval 设置完的等待时间
- VC获取进程启动和结束时间
- 获取和设置系统时间
- PHP设置COOKIE保留时间为浏览器进程
- 获取进程运行的时间源代码
- WinAPI: GetLocalTime、SetLocalTime、SetSystemTime - 获取与设置系统时间
- 【转载】Delphi获取与设置系统时间格式(长日期与短日期)
- 设置进程的优先级
- js设置获取gmt时间
- 动态获取media的URL及设置时间格式
- 获取(设置)系统时间
- Java 通过 JNA (Java Native Access) 获取、设置 Windows 操作系统的文件创建时间、文件修改时间、文件访问时间
- PHP获取系统时间,时区设置问题
- VB设置进程优先级
- WinAPI: GetDoubleClickTime、SetDoubleClickTime - 获取与设置鼠标双击间隔时间
- 正确获取或设置CrmDateTime中的日期和时间值
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第十五节 设置本机默认的生存时间(time-to-live:TTL)值
- 设置进程优先级