LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 922|回复: 6

我的操作系统作业

[复制链接]
发表于 2002-11-10 23:25:51 | 显示全部楼层 |阅读模式
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
pid_t p1,p2,p3,p4;
int  main(void){
  int Randomnum(void);  
                       
struct stares1{ int s;   char r1[10]; }statue1={0,"ABCDEFGHIJ"};
struct stares2{ int s;   char r2[10]; }statue2={0,"KLMNOPQRST"};
struct stares3{ int s;   char r3[10]; }statue3={0,"UVWXYZabcd"};
struct stares4{ int s;   char r4[10]; }statue4={0,"efghijklmn"};
struct stares5{ int s;   char r5[10]; }statue5={0,"opqrstuvwx"}
struct pidstatue{         
    char name[2];            
    int  renum;         
    int  given;              
    int  nogiven;   } * capro[4];              
                                          
    capro[0]->name[2] = "p1";  capro[0]->renum = 3;
  capro[1]->name[2] = "p2";    capro[1]->renum = 2;
  capro[2]->name[2] = "p3";   capro[2]->renum = 2;
capro[3]->name[2] = "p4";    capro[3]->renum = 4;
int sysgiven = 5;
Randomnum();
if(p1<0)   {   
    printf(" fork error\n ");     exit();   }
else if( (p1==0) || (p1==1) )  
  {if((capro[0]->renum <= sysgiven) && (capro->nongive <=sysgiven))   
       {  if((statue1->s=0)&&(capro[0]->given<3)) { capro[0]>given++;      
        sysgiven--;       printf("%s\n",statue1->r1[10]);      statue1->s = 1; }          
   if((statue2->s=0)&&(capro[0]->given<3)) { capro[0]->given++;     
          sysgiven--;       printf("%s\n",statue2->r2[10]);      statue2->s = 1; }      
      if((statue3->s=0)&&(capro[0]->given<3)) { capro[0]->given++;
              sysgiven--;       printf("%s\n",statue3->r3[10]);      statue3->s = 1; }
            
             if((statue4->s=0)&&(capro[0]->given<3)) { capro[0]->given++;
              sysgiven--        printf("%s\n",statue4->r4[10]);      statue4->s = 1; }
             if((statue5->s=0)&&(capro[0]->given<3)) { capro[0]->given++;
            sysgiven--        printf("%s\n",statue5->r5[10]);     statue5->s = 1 ; }
             sysgiven = 5;     exit();
             } else printf(" Dead \n");          }
  Randomnum();
if(p2<0)  {   printf(" fork error\n " );    exit(1);   }
else if((p2==0) || (p2==1))  
{      if((capro[1]->renum <= sysgiven) && (capro->nongive <= sysgiven))  
          {   if((statue1->s=0)&&(capro[1]->given<3)) { capro[1]->given++;  
sysgiven--;       printf("%s\n",statue1->r1[10]);      statue1->s = 1; }     
   if((statue2->s=0)&&(capro[1]->given<3)) { capro[1]->given++;
             sysgiven--;       printf("%s\n",statue2->r2[10]);      statue2->s = 1; }  
           if((statue3->s=0)&&(capro[1]->given<3)) { capro[1]->given++;      
        sysgiven--;       printf("%s\n",statue3->r3[10]);      statue3->s = 1; }
if((statue4->s=0)&&(capro[1]->given<3)) { capro[1]->given++;
           sysgiven--        printf("%s\n",statue4->r4[10]);      statue4->s = 1; }
             if((statue5->s=0)&&(capro[1]->given<3)) { capro[1]->given++;   
            sysgiven--        printf("%s\n",statue5->r5[10]);     statue5->s = 1 ; }   
   sysgiven = 5;     exit();             } else printf(" Dead \n");     }
Randomnum();
if( p3<0 ) {    printf(" fork error\n " );    exit(1); }
  else if((p3==0) || (p3==1))
  {       if((capro[2]->renum <= sysgiven) && (capro->nongive <= sysgiven))
           {    if((statue1->s=0)&&(capro[2]->given<3)){ capro[2]->given++;   
          sysgiven--;       printf("%s\n",statue1->r1[10]);    statue1->s = 1; }   
   if((statue2->s=0)&&(capro[2]->given<3)) { capro[2]->given++;
               sysgiven--;       printf("%s\n",statue2->r2[10]);      statue2->s = 1; }
             if((statue3->s=0)&&(capro[2]->given<3)) { capro[2]->given++;   
           sysgiven--;       printf("%s\n",statue3->r3[10]);      statue3->s = 1; }            
         if((statue4->s=0)&&(capro[2]->given<3)) { capro[2]->given++;
          sysgiven--        printf("%s\n",statue4->r4[10]);      statue4->s = 1; }
             if((statue5->s=0)&&(capro[2]->given<3)) { capro[2]->given++;
             sysgiven--        printf("%s\n",statue5->r5[10]);     statue5->s = 1 ; }
              sysgiven = 5;    exit();     }
else printf(" Dead \n");       }
Randomnum();
if( p4<0 ) {   printf(" fork error\n " );    exit(1); }
  else if((p4==0) || (p4==1))
   {   if((capro[3]->renum <= sysgiven) && (capro->nongive <= sysgiven))
             {        if((statue1->s=0)&&(capro[3]->given<3)) { capro[3]->given++;
             sysgiven--;       printf("%s\n",statue1->r1[10]);      statue1->s = 1; }
     if((statue2->s=0)&&(capro[3]->given<3)) { capro[3]->given++;
       sysgiven--;       printf("%s\n",statue2->r2[10]);      statue2->s = 1; }         
    if((statue3->s=0)&&(capro[3]->given<3)) { capro[3]->given++;
            sysgiven--;       printf("%s\n",statue3->r3[10]);      statue3->s = 1; }   
         if((statue4->s=0)&&(capro[3]->given<3)) { capro[3]->given++;
              sysgiven--        printf("%s\n",statue4->r4[10]);      statue4->s = 1; }
             if((statue5->s=0)&&(capro[3]->given<3)) { capro[3]->given++;
sysgiven--        printf("%s\n",statue5->r5[10]);     statue5->s = 1 ; }       
      sysgiven = 5;     exit();          } else printf(" Dead \n");        }  }  
int Radomnum(void)  
  {     int i;     
  i = random();     
i = i%4;     
switch(i){     
case 0 :  p1 = fork(); break;
     case 1 :  p2 = fork(); break;
    case 2 :  p3 = fork(); break;
    case 3 :  p4 = fork(); break;
   }   return;   }
发表于 2002-11-11 09:10:05 | 显示全部楼层
老兄还是先检查一下struct里面的->和 。的用法吧,还有有很多成员敲错了!有的变量没有初始化就进行四则运算。
 楼主| 发表于 2002-11-11 10:12:12 | 显示全部楼层
提示错误:
Segmention default  是什么意思 ?
发表于 2002-11-11 11:24:42 | 显示全部楼层

Segmention default

这个一般是指针的问题,你好好看看指针都对吗?
发表于 2002-11-11 13:53:25 | 显示全部楼层
segmention fault是指程序访问了不该访问的内存地址,被操作系统强制停止运行后返回的错误信息。多半是指针出了问题。
 楼主| 发表于 2002-11-11 17:33:45 | 显示全部楼层
 !谢谢大家 
 楼主| 发表于 2002-11-11 17:34:24 | 显示全部楼层
那提示: assign makes integer from pointer without a cast
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表