2 Replies - 11267 Views - Last Post: 28 December 2009 - 08:24 AM Rate Topic: -----

#1 aspire001  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-December 09

nonpreemptive scheduling

Posted 28 December 2009 - 07:44 AM

#include<stdio.h>
#include<malloc.h>
int* getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess);
int main()
{
	int nProcess=3;
	int *process=(int *)malloc(2*nProcess);
	int *arrivalTime=(int*)malloc(2*nProcess);
	int *burstTime=(int*)malloc(2*nProcess);
	int proc[]={1,2,3};
	int aTime[]={0,4,8};
	int bTime[]={6,2,1};
	int *a=(int *)malloc(2*nProcess);
	int i;
	for(i=0;i<nProcess;i++)
	{
		process[i]=proc[i];
		arrivalTime[i]=aTime[i];
		burstTime[i]=bTime[i];
	}
a=getWaitingTime(process,arrivalTime,burstTime,nProcess);
	if(a!=NULL)
	{
	for(i=0;i<nProcess;i++)
	printf("%d\t",*(a+i));
	}
	else
	printf("The function getWaitingTime returns NULL");
	free(a);
	return 0;
}
int* getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess)
{
	int i;
	int sum[10];
	int bur[10];
	int flag[10];
	int *a=(int*)malloc(2*nProcess);
	int sump=*burstTime;
	int sumn;
	int j;
	int k;
	int p;
	int t;
	if((*(arrivalTime)!=0) ||(*burstTime<0)||(*burstTime>10))
		return (NULL);
	for(i=1;i<nProcess;i++)
		if((*(arrivalTime+i)==0)||(*(burstTime+i)<0)||(*(burstTime+i)>10))
			return (NULL);
	for(i=0;i<nProcess;i++)   {
		sum[i]=*(arrivalTime+i)+*(burstTime+i);
	}
	bur[0]=*(burstTime);
	for(i=1;i<nProcess;i++)
		flag[i]=0;
	flag[0]=1;
	for(i=1;i<nProcess;i++)
	{
		if(flag[i]==0)
		{
		sumn=0;
		for(j=i;j<nProcess;j++)
		{
			if(flag[j]==0){
			sumn=sumn+*(arrivalTime+j);
			if(sumn>sump)
				break;
			}
		}
		k=j-1;
		t=*(burstTime+i);
		p=i;
		for(j=i+1;j<=k;j++)
		{
			if(flag[j]==0){
			if(*(burstTime+j)<t)
			{
				t=*(arrivalTime+j);
				p=j;
			}
			}
		}
		sump+=*(burstTime+p);
		bur[p]=sump;
		flag[p]=1;
		if(p!=i)
		i=i-1;
		}
	}
	for(i=0;i<nProcess;i++)
	{
	*(a+i)=bur[i]-sum[i];
	}
	process=a;
	return (process);
}




This program is giving me correct output. but while submitting i am getting the following error.

on Preemptive Scheduling:
Following test cases failed in your program; If you would like you can correct and do "Submit solution" again:
1. Test case failed with normal inputs for function: getWaitingTime()

Error:
*** glibc detected *** output/cnonpreemptivescheduling/testnonpreemptive.exe: free(): invalid size: 0x098e21a8 ***
======= Backtrace: =========
/lib/libc.so.6[0x721b16]
/lib/libc.so.6[0x7227a2]
/lib/libc.so.6(__libc_malloc+0x7e)[0x72335e]
/lib/ld-linux.so.2[0x6a7b62]
/lib/ld-linux.so.2[0x6acafd]
/lib/ld-linux.so.2[0x6a8e36]
/lib/ld-linux.so.2[0x6ac482]
/lib/libc.so.6[0x7bf722]
/lib/ld-linux.so.2[0x6a8e36]
/lib/libc.so.6(__libc_dlopen_mode+0x55)[0x7bf8d5]
/lib/libpthread.so.0[0x83aaf7]
/lib/libpthread.so.0[0x83ac21]
/lib/libpthread.so.0(__pthread_unwind+0x51)[0x8386f1]
/lib/libpthread.so.0(pthread_detach+0x0)[0x8333c0]
output/cnonpreemptivescheduling/testnonpreemptive.exe(__gxx_personality_v0+0x1a8)[0x8048e5c]
output/cnonpreemptivescheduling/testnonpreemptive.exe[0x804962c]
output/cnonpreemptivescheduling/testnonpreemptive.exe[0x8049182]
/lib/libpthread.so.0[0x83245b]
/lib/libc.so.6(clone+0x5e)[0x789c4e]
======= Memory map: ========
002c5000-003a5000 r-xp 00000000 fd:00 23359473 /usr/lib/libstdc++.so.6.0.8
003a5000-003a9000 r-xp 000df000 fd:00 23359473 /usr/lib/libstdc++.so.6.0.8
003a9000-003aa000 rwxp 000e3000 fd:00 23359473 /usr/lib/libstdc++.so.6.0.8
003aa000-003b0000 rwxp 003aa000 00:00 0
0069b000-006b5000 r-xp 00000000 fd:00 6490409 /lib/ld-2.5.so
006b5000-006b6000 r-xp 00019000 fd:00 6490409 /lib/ld-2.5.so
006b6000-006b7000 rwxp 0001a000 fd:00 6490409 /lib/ld-2.5.so
006b9000-007f6000 r-xp 00000000 fd:00 6490410 /lib/libc-2.5.so
007f6000-007f8000 r-xp 0013d000 fd:00 6490410 /lib/libc-2.5.so
007f8000-007f9000 rwxp 0013f000 fd:00 6490410 /lib/libc-2.5.so
007f9000-007fc000 rwxp 007f9000 00:00 0
007fe000-00823000 r-xp 00000000 fd:00 6490417 /lib/libm-2.5.so
00823000-00824000 r-xp 00024000 fd:00 6490417 /lib/libm-2.5.so
00824000-00825000 rwxp 00025000 fd:00 6490417 /lib/libm-2.5.so
0082d000-00840000 r-xp 00000000 fd:00 6490412 /lib/libpthread-2.5.so
00840000-00841000 r-xp 00012000 fd:00 6490412 /lib/libpthread-2.5.so
00841000-00842000 rwxp 00013000 fd:00 6490412 /lib/libpthread-2.5.so
00842000-00844000 rwxp 00842000 00:00 0
00c38000-00c43000 r-xp 00000000 fd:00 6490432 /lib/libgcc_s-4.1.2-20080102.so.1
00c43000-00c44000 rwxp 0000a000 fd:00 6490432 /lib/libgcc_s-4.1.2-20080102.so.1
08048000-0804c000 r-xp 00000000 00:12 9780811 output/cnonpreemptivescheduling/testnonpreemptive.exe
0804c000-0804d000 rwxp 00003000 00:12 9780811 output/cnonpreemptivescheduling/testnonpreemptive.exe
098e2000-09925000 rwxp 098e2000 00:00 0
b7400000-b7421000 rwxp b7400000 00:00 0
b7421000-b7500000 ---p b7421000 00:00 0
b7559000-b755a000 ---p b7559000 00:00 0
b755a000-b7f5c000 rwxp b755a000 00:00 0
b7f69000-b7f6b000 rwxp b7f69000 00:00 0
b7f6b000-b7f6c000 r-xp b7f6b000 00:00 0 [vdso]
bfa45000-bfa5a000 rw-p bfa45000 00:00 0 [stack]

Is This A Good Question/Topic? 0
  • +

Replies To: nonpreemptive scheduling

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: nonpreemptive scheduling

Posted 28 December 2009 - 08:00 AM

You don't go out of your way to tell your story in a clear and complete manner do you?
Took me a few minutes to work out what you were trying to tell us.
I nearly gave up but then I thought I might have guessed it.
Have I guessed what is going on?
Is this a fuller explanation of what is happening?

-------
I have written this program as homework.
It passes all my testing.
But, when I submit my homework to my school the school applies some test data to the program and my program fails that testing.

The messages returned from the school automatic testing tool are...

--------

Assuming I have guessed what it is you were trying to tell us then my first question would be to ask if you know what the school's testing tools applied to your program?

Are you able to replicate the test that the school says your program is failing to handle?
Was This Post Helpful? 0
  • +
  • -

#3 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: nonpreemptive scheduling

Posted 28 December 2009 - 08:24 AM

I got your code to compile by removing <malloc.h> and including <stdlib.h> instead.

Your code just spits out a few numbers.

I am only guessing but it seems that the test applied by your school is trying to provide some inputs to your program.
Do your requirements speak of accepting inputs?
You don't seem to have allowed any inputs.

Can you clarify that for us?

Could I also suggest that you could invest 30 minutes in going through your code and indenting everything consistently and deciding on which brace style you want to use and applying just the one style instead of mixing them in the same program. You might even drop a few well chosen empty lines and a smattering of comments to help the reader. Your code is less than completely clear in its current form.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1