By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

Runtime Error "glibc detected"

P: 4
Expand|Select|Wrap|Line Numbers
  1. /* While running the program a runtime error occurs."glibc detected" followed by a lot of memory address/instruction errors. Please help rectify this error.*/
  2.  
  3. /*Header file:"nonpreemptive.h" is as follows:
  4. #define C_OR_CPP 2 //  Change value to 1 here if you are submitting a C solution for this problem.
  5.                    //  Change value to 2 here if you are submitting a C++ solution for this problem.
  6.  
  7.  
  8.  
  9. void dsmain();
  10.  
  11. #if C_OR_CPP == 1  // Don't change here
  12.  
  13.     int* getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess);
  14.  
  15. #endif
  16.  
  17.  
  18.  
  19. #if C_OR_CPP == 2  // Don't change here
  20.  
  21. class NonPreemptive
  22. {
  23.  public:
  24.      int* getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess);
  25. };
  26.  
  27. #endif
  28. */
  29.  
  30. #include<iostream>
  31. #include"nonpreemptive.h"
  32. using namespace std;
  33. NonPreemptive s1;
  34. int* NonPreemptive::getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess)
  35. {
  36. if(arrivalTime[0]!=0)
  37. {
  38. return NULL;
  39. }
  40. int g=0,h=0;
  41. for(g=0;g<nProcess;++g)
  42. {
  43. for(h=g+1;h<nProcess;++h)
  44. {
  45. if(arrivalTime[g]==arrivalTime[h])
  46. {
  47. return NULL;
  48. }
  49. if(arrivalTime[g]>arrivalTime[h])
  50. {
  51. return NULL;
  52. }
  53. if(burstTime[g]<0||burstTime[g]>10)
  54. {
  55. return NULL;
  56. }
  57. }
  58. }
  59. int done=0,min=0,CPU=0,x=0,i=0;
  60. int* result;
  61. result=new int;
  62. while(done<nProcess)
  63. {
  64. min=20000;
  65. for(i=0;i<nProcess;++i)
  66. {
  67. if(process[i]>0)
  68. {
  69. if(arrivalTime[i]<=CPU)
  70. {
  71. if(arrivalTime[i]+burstTime[i]<min)
  72. {
  73. min=arrivalTime[i]+burstTime[i];
  74. x=i;
  75. }
  76. }
  77. }
  78. }
  79. result[x]=CPU-arrivalTime[x];
  80. CPU+=burstTime[x];
  81. ++done;
  82. process[x]=-1;
  83. }
  84. return result;
  85. }
  86. int main()
  87. {
  88.     {    int* output;    
  89.         int nProcess = 7;
  90.         int* process = (int*)malloc(sizeof(int) * nProcess);
  91.         int* arrivalTime = (int*)malloc(sizeof(int) * nProcess);
  92.         int* burstTime = (int*)malloc(sizeof(int) * nProcess);
  93.  
  94.         int proc[] = {1,2,3,4,5,6,7};
  95.         int aTime[] = {0,2,4,6,8,10,12};
  96.         int bTime[] = {6,2,5,4,1,3,5};
  97.  
  98.         for(int i=0;i<nProcess;i++)
  99. {
  100.             process[i] = proc[i];
  101.             arrivalTime[i] = aTime[i];
  102.             burstTime[i] = bTime[i];
  103.         }
  104.  
  105.         output = s1.getWaitingTime(process, arrivalTime, burstTime, nProcess);
  106.         printf("\n");
  107.         if(output != NULL)
  108.             for(int i=0;i<nProcess;i++)
  109.                 printf ("%d, ",output[i]);
  110.         else printf("NULL");
  111.     }
  112. return(0);
  113. }
  114.  
  115.  
Nov 25 '09 #1
Share this Question
Share on Google+
1 Reply


100+
P: 687
Did you try to run in under debugger to see where it crashes?
Nov 25 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.