当前位置: 技术问答>linux和unix
关于子linux进程调度的问题
来源: 互联网 发布时间:2016-01-27
本文导语: 我 有一个 程序,是想让五个子进程一个一个地打印出信息,但是程序实现的是五个进程一起打印出来了,怎么改才能实现呢? 麻烦给看看 #include "stdio.h" #include #include #include #include #include #include #include #...
我 有一个 程序,是想让五个子进程一个一个地打印出信息,但是程序实现的是五个进程一起打印出来了,怎么改才能实现呢? 麻烦给看看
#include "stdio.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
pid_t pid[5];
void kill_process()
{
exit(0);
}
/*显示进程调度策略和优先级的信息*/
void show_info(pid_t pid)
{
struct sched_param sp;
int policy;
policy = sched_getscheduler(pid);
if (policy == -1) {
perror("sched_getscheduler");
fprintf(stderr, "failed to get pid %d's policyn", pid);
exit(1);
}
printf("scheduling policy: ");/*打印进程的调度策略*/
switch (policy) {
case SCHED_OTHER:
printf("SCHED_OTHERn");
break;
case SCHED_FIFO:
printf("SCHED_FIFOn");
break;
case SCHED_RR:
printf("SCHED_RRn");
break;
default:
printf("unknownn");
}
if (sched_getparam(pid, &sp)) {
perror("sched_getparam");
fprintf(stderr, "failed to get pid %d's attributesn", pid);
exit(1);
}
printf("scheduling priority: %dn", sp.sched_priority);/*打印进程的优先级*/
}
void user_fork(int i)
{
char outstr[20];
if ((pid[i] = fork())
#include "stdio.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
pid_t pid[5];
void kill_process()
{
exit(0);
}
/*显示进程调度策略和优先级的信息*/
void show_info(pid_t pid)
{
struct sched_param sp;
int policy;
policy = sched_getscheduler(pid);
if (policy == -1) {
perror("sched_getscheduler");
fprintf(stderr, "failed to get pid %d's policyn", pid);
exit(1);
}
printf("scheduling policy: ");/*打印进程的调度策略*/
switch (policy) {
case SCHED_OTHER:
printf("SCHED_OTHERn");
break;
case SCHED_FIFO:
printf("SCHED_FIFOn");
break;
case SCHED_RR:
printf("SCHED_RRn");
break;
default:
printf("unknownn");
}
if (sched_getparam(pid, &sp)) {
perror("sched_getparam");
fprintf(stderr, "failed to get pid %d's attributesn", pid);
exit(1);
}
printf("scheduling priority: %dn", sp.sched_priority);/*打印进程的优先级*/
}
void user_fork(int i)
{
char outstr[20];
if ((pid[i] = fork())