问题描述
- linux终端vim操作系统模拟问题
-
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> int main( void ) { struct process{ char pname[3]; char *next; int act; int runt; char sta; }; int a[5]; int i,j=0,m,n,u=1,o; int current; struct process s[5]; strcpy(s[1].pname,"Q1"); strcpy(s[2].pname,"Q2"); strcpy(s[3].pname,"Q3"); strcpy(s[4].pname,"Q4"); strcpy(s[5].pname,"Q5"); s[1].runt = 0; s[2].runt = 0; s[3].runt = 0; s[4].runt = 0; s[5].runt = 0; s[1].sta='R'; s[2].sta='R'; s[3].sta='R'; s[4].sta='R'; s[5].sta='R'; srand(time(NULL)); for(i=1;i<6;i++) { s[i].act = rand()%8+1; } for(m=1;m<10;m++) for(n=1;n<6;n++) { if(s[n].sta == 'E') continue; printf(" Ronud%d: ",u); u++; current = n; s[n].runt = s[n].runt + 1; sleep(1); if(s[n].runt == s[n].act) { s[n].sta = 'E'; a[j] = n; j++; } printf("RunningProcess:s%d PlanTime:%d RunTime:%d state:%c",current,s[n].act,s[n].runt,s[n].sta); printf(" The Order Of Running Process: "); for(o=1;o<6;o++) { if(s[o].sta == 'E') continue; else { printf("s%d ",o); } } printf(" The Order Of Block Process: "); for(o=1;o<6;o++) { if(s[o].sta == 'E') printf("s%d ",o); else continue; } printf(" ******************************************************************* "); } printf("The Order of The end Process: "); for(i=0;i<5;i++) { printf("The %d of th end Process is s%d ",i+1,a[i]); } return 0; }
老师布置的一道操作系统作业题,要求在linux终端下使用c语言模拟操作系统调用进程,代码已经摸索出= =,但是运行结果不尽如人意,最后出现——段错误(核心已转储),不知道出现原理以及解决办法,求大神帮帮忙,谢谢啦!
解决方案
解决方案二:
用gdb调试一下core文件定位错误
解决方案三:
你定义的结构体中 char * 成员变量没分配内存。
时间: 2024-10-24 19:04:15