|
[code:1]
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
struct proc{
char name[2];
int num;
struct proc *next;
};
int n;
struct proc *head, *this, *new, *current, *temp;
void new_record(void);
void sortlist(void);
void excutable(void);
pid_t pid;
main ()
{
int i, j;
for(i=0; i<=8; i++){
new_record();
}
sortlist();
excutable();
for(j=1; j<=7; j++){
current = head;
excutable();
if(n>2){
do{
this->num = this->num+1;
if(this->num > 32){
this->num = this->num%32;
sortlist();
}
this = this->next;
}while(this->next = NULL);
}
free(new);
}
} //lost a '}'
void new_record(void)
{
int i;
new = (struct proc *)malloc(sizeof (struct proc));
if(head == NULL)
head = new;
else{
this = head;
while(this->next!=NULL)
this = this->next;
this->next = new;
}
this = new;
printf("\nenter name:"); //what did u mean of '\e'??
scanf("%s",this->name);
printf("\nenter num:"); //what did u mean of '\e'??
this->num = i;
printf("\n new over");
this->next = NULL;
}
void sortlist(void)
{
int i,j;
this = head;
for(i=1; i<=8; i++)
for(j=i+1; j<=8; j++){
if(this->num < this->next->num){
temp = this;
this = this->next;
this->next = temp;
}
this = this->next;
}
}
void excutable(void)
{
n = random()%4;
current = head;
pid=fork();
if ( pid>0 ){
sleep(n);
}
}
[/code:1] |
|