linux 实时进程配置,linux进程 设置优先级 example (linux 1~99 实时)

linux2.6优先级为0-139,其中100-139为普通进程,0-99为实时进程。

/*pri.c*/

#include

#include

#include

#include

#include

#include

int main(int argc,char *argv[])

{

unsigned int i=0,j=0,k=0,h;

nice(-1);

int pid[1];

struct sched_param p[1];

printf("max_pri is:%d,min_pri:%d\n ",sched_get_priority_max(2),sched_get_priority_min(2));

struct sched_param para;

para.sched_priority =23;

sched_setscheduler(0,SCHED_FIFO,&para);

printf("Parent pid is %d policy is %d, prio: %d\n",getpid(),sched_getscheduler(0),para.sched_priority);

while(1);

}

按照以下步骤:

gcc -o pri pri.c

./pri &

[root@FPC10 zhisxu]# ./pri

max_pri is:99,min_pri:1

Parent pid is 9461 policy is 1, prio: 23

[root@FPC10 ~]# top

top - 12:51:57 up 13 days, 3:18, 6 users, load average: 1.54, 0.57, 0.25

Tasks: 116 total,   3 running, 113 sleeping,   0 stopped,   0 zombie

Cpu(s): 87.5%us, 7.3%sy, 0.0%ni, 5.0%id, 0.0%wa, 0.0%hi, 0.2%si, 0.0%st

Mem:   2031980k total,   901064k used, 1130916k free,   272964k buffers

Swap: 2031608k total,        0k used, 2031608k free,   499884k cached

PID USER      PR NI VIRT RES SHR S %CPU %MEM    TIME+ COMMAND

9461 root    -24 -1 1500 328 276 R 100 0.0   1:39.03 pri

好像应该也可以用下面这种方法实现:pid=getpid();

sched_setscheduler(pid,SCHED_FIFO, &param);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值