|
我使用RedHat Linux 9.0,用Emacs写了一个小程序,目的是使用一下几个系统调用,比如这里提到的sched_getparam()。源程序如下:
#include <sched.h>
#include <stdio.h>
#include <errno.h>
int main()
{
errno=0;
int retval;
struct sched_param *p;
if((retval=sched_getparam(0,p))==-1)
{
printf("systemcall sched_getparam fail\n");
if(errno)
perror("sched_getparam");
exit(0);
}
printf("%ld\n",p->sched_priority);
}
运行结果如下:
systemcall sched_getparam fail
sched_getparam Bad address
我详细阅读了该系统调用的说明书页,没有找到错误所在。errno对应的信息是Bad address。请哪位大哥执教一二。感激不尽。
还有一个关于系统调用sched_setscheduler()的问题,源程序如下:
#include <sched.h>
#include <stdio.h>
#include <errno.h>
int main()
{
errno=0;
int retval;
struct sched_param *p;
p->sched_priority=10;
if((retval=sched_setscheduler(0,SCHED_FIFO,p))==-1)
{
printf("systemcall sched_setscheduler fail\n");
if(errno)
perror("sched_setscheduler");
exit(0);
}
printf("%ld\n",p->sched_priority);
}
运行结果如下:
断错误
我实在想不出错在那里,盼望好心人指教。 |
|