السلام عليكم ورحمة الله وبركاته
لدي كود بلغة
c
خاص بنوع من
cpu scheduling
وهو
Shortest Job First (SJF)
لكن به بعض الاخطاء كما أني أحتاج لمن يقوم بشرحه لي
هل بإمكانكم مساعدتي
شكرآ لكم
السلام عليكم ورحمة الله وبركاته
لدي كود بلغة
c
خاص بنوع من
cpu scheduling
وهو
Shortest Job First (SJF)
لكن به بعض الاخطاء كما أني أحتاج لمن يقوم بشرحه لي
هل بإمكانكم مساعدتي
شكرآ لكم
أين هو الكود و من أين أتيت به :D.
''اللهم إني أسالك إيمانا دائما وأسألك قلبا خاشعا وأسألك علما نافعا وأسألك يقينا صادقا وأسألك دينا قيما وأسألك العافية من كل بلية''
'اللهم أغفر للمؤمنين و المؤمنات و المسلمين و المسلمات الأحياء منهم و الأموات'
www.it-scoop.com
SIFE كتب:أين هو الكود و من أين أتيت به :D .
صديقة لي قامت بكتابته من أجل مشروع لها
الكود في الملف المرفق
هل لديك برنامج
DevC++
لتقوم بتشغيله مباشرة
إن لم تستطيع فسأقوم بعمل كوبي للكود هنا
شكرأ لطيب المبادرة
أخي الكريم هل اطلعت على الملف ..
أتمنى أن تكون هناك إمكانية لمساعدتي ..
بارك الله فيك ..
السلام عليكــم ورحمـة الله وبركاتــه ،،
تفضل أخى الكود بدون أخطاء ان شاء الله
فى المرفقات
اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم
amin_mu123 كتب:السلام عليكــم ورحمـة الله وبركاتــه ،،
تفضل أخى الكود بدون أخطاء ان شاء الله
فى المرفقات
وعليكم السلام ورحمة الله وبركاته
أخي الكريم شكرآ لأصالتك وطيب ردك .
قمت بتجريب الكود
عندما أدخل عدد ال
job
أكبر من 1
وأقوم بعمل
Run
فيكون الناتج عملية غير منتهية ولا يتوقف إلا بعد أن أغلق النافذة
لكن إذا ادخلت رقم أقل من صفر فإن الشرط يعمل بطريقة صحيحة
لا أدري ما المشكلة ..
هل بإمكانك أخي الفاضل الإطلاع عليه مرة أخرى
أكرمك الله بكل خير
أختك
تم تعديل هذه المشاركة بواسطة Nuwar11 في 15 مايو 2009 في 10:59
السلام عليكم
كان هناك خطأ فى الكود
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<malloc.h>
struct PCB
{
int pid; //Process ID ,Generated Randomly (100-500)
int cpu_time; //CPU Burst ,Generated Randomly (10-50)
int wt; //Waiting Time ,Calculated
int response_t; //Response Time ,Calculated
int turnarround_t; //Turnaround Time ,Calculated
int jobno; //Job Number 1,2,3,…………..,N
int a_time; //Arrival Time is equal in all PCB's=0
int pc; //Program Counter, Generated Randomly (111-999)
char status; //Ready State "R"
char flag; //Interrupt Flag "E" or "D"
struct PCB *nextptr; //Pointer to next Node
};
typedef struct PCB pcb;
typedef pcb* PCBPTR;
int main()
{
PCBPTR head=NULL, tail=NULL, ptr1, ptr2;
int pid, cpu_time ,pc, a_time=0, jobno;
char answer='a',flag='E',status='N';
int p ,c,w,no,turnarround_t,response_t;
int n,i;
float sum_rt=0,sum_tt=0;
float h;
srand(time(0));
printf("Enter no of jobs: ");
scanf("%d",&n);
if(n<=0)
{
printf("You did not enter any process\n");
printf("Enter a number that is greater than zero please : ");
scanf("%d",&n);
}
else{
printf("The processes when they arrive : \n\n");
printf("H Process pid Ct AT waiT RespT TurnT flag Status PC next H\n");
while(answer!='n' && answer!='N')
{
for(i=1;i<=n;i++)
{
pid=rand()%(400)+100;
cpu_time=rand()%(40)+10;
pc=rand()%899+111;
PCBPTR newptr;
newptr=(PCBPTR)malloc(sizeof(pcb));
jobno=i;
newptr->pid=pid;
newptr->cpu_time=cpu_time;
newptr->nextptr=NULL;
newptr->a_time=a_time;
newptr->flag=flag;
newptr->status=status; //processes before going to the ready queue,when they arrive
printf(" P(%d) ",jobno);
printf(" %d ",pid);
printf("(%d) ",cpu_time);
printf(" %d ",a_time);
printf("\t\t\t %c ",flag);
printf(" %c ",status);
printf(" %d ",pc);
printf(" ==> ",newptr->nextptr); // the newptr->next value is null ,so it will not appear.
printf("\n");
PCBPTR newPtr;
newPtr=(PCBPTR)malloc(sizeof(pcb));
if(newPtr !=NULL)
{
newPtr->pid=pid;
newPtr->cpu_time=cpu_time;
newPtr->jobno=i;
newPtr->nextptr=NULL;
newPtr->a_time=0;
newPtr->pc=pc;
if(i==1)
{
head=newPtr;
tail=newPtr;
}
else if(head->cpu_time>cpu_time) //add the node to the head
{
newPtr->nextptr=head;
head=newPtr;
}
else if(tail->cpu_time<=cpu_time) //add the node to the tail
{
tail->nextptr=newPtr;
tail=newPtr;
}
else
{
for(ptr1=head,ptr2=head->nextptr;ptr2->cpu_time<=cpu_time;ptr1=ptr1->nextptr,ptr2=ptr2->nextptr);
newPtr->nextptr=ptr2;
ptr1->nextptr=newPtr;
}
}
else
printf("No memory \n");
}
if(head==NULL)
printf("The Queue is: \n");
else
{
PCBPTR currentPtr=head;
printf("\n");
int WT=0, prevcpuburst=0,wt=0;
float S=0; // S is the Sum
printf("Process AT pid Ct waiT RespT TurnT flag Status PC \n");
while(currentPtr != NULL)
{
WT=WT+prevcpuburst;
currentPtr->wt=WT;
response_t=WT;
turnarround_t=WT+currentPtr->cpu_time;
currentPtr->flag='E';
currentPtr->status='R';
printf("p(%d)\t%d\t%d\t%d\t%d\t%d\t%d\t%c\t%c\t%d \n\n\n",currentPtr->jobno,
currentPtr->a_time,currentPtr->pid,currentPtr->cpu_time,currentPtr->wt,response_t,
turnarround_t,currentPtr->flag,currentPtr->status,currentPtr->pc);
prevcpuburst=currentPtr->cpu_time;
currentPtr=currentPtr->nextptr;
S+=WT;
sum_tt+=turnarround_t;
sum_rt+=response_t;
}
printf("Average Waiting Time = %f\n",S/n);
printf("Average Responce Time = %f\n",sum_rt/n);
printf("Average Turn Arround Time = %f\n\n",sum_tt/n);
}
printf(" Do You Want to proceed? \n");
printf(" Yes (Y) No (N) \n");
scanf("%s",&answer);
printf(" \n");
// you want to re do what you have done before
if(answer=='y' || answer=='Y')
{
printf("Enter another number of jobs: ");
scanf("%d",&n);
while(n<=0)
{
printf(" There is no processes .. Please Enter a number greater than zero \n");
printf("Enter no of jobs: ");
scanf("%d",&n);
}
}
for(ptr1=head;ptr1->nextptr!=NULL;ptr1=ptr1->nextptr)
free(ptr1);
h=clock();
printf("Execution time in milli seconds = %f ms \n\n",h);
h=0;
}
}
return(0);جربيه ؟؟؟ هل أدى المطلوب منه؟؟
فى أمان الله
اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم
أخي الكريم amin_mu123
شكرآ بعمق .. لقد أدى المطلوب بصورة صحيحة ..
جزاك الله كل خير ..
طلب أخير إن كان بإمكانك أن تشرح لي الكود بصورة مختصرة ..
أو تفسر لي بعض الجمل ما عملها ..
أكون ممتنة كثيرآ لك .. وإن لم يكن لديك متسع من الوقت فلا داعي ..
بارك الله فيك ...