Linked list coding for CPU scheduling algorithms help with pointers

ayeswarya -1 Tallied Votes 3K Views Share
struct PCB* handleProcessArrival_PP(struct PCB *processhead,struct PCB *processtail,struct PCB *currProcess,struct PCB *newProcess,int currTime){
    if(currProcess==NULL){
       newProcess->executionStartTime = currTime;
       newProcess->executionEndTime = currTime+newProcess->totalBurstTime;
       newProcess->remainingBurstTime = newProcess->totalBurstTime;
       if(newProcess->processID==processhead->processID){
          processhead= newProcess->next;
          printf("processhead in case 1 %d \n",processhead->processID);
       }
       currProcess=newProcess; 
       printf("***current process = new process%d \n",currProcess->processID);
       contents(processhead);
       return currProcess;
       //return processhead;
       
    }
    if (currProcess->processID !=0){
       contents(processhead);
       if(currProcess->processPriority>newProcess->processPriority){//new process higher priority
         printf("***new process in handle %d \n",newProcess->processID);
         currProcess->executionStartTime = 0;
         currProcess->executionEndTime = 0;
         currProcess->remainingBurstTime = currProcess->totalBurstTime-(currProcess->executionStartTime-currTime);
         processtail->next=currProcess;
         processtail=currProcess;
         newProcess->executionStartTime=currTime;
         newProcess->executionEndTime = currTime+newProcess->totalBurstTime;
         newProcess->remainingBurstTime = newProcess->totalBurstTime;
         currProcess=newProcess;
         printf("current process replaced with%d \n",newProcess->processID);
         printf("processhead in case 2 %d \n",processhead->processID);
         return currProcess;
       } 
       if(currProcess->processPriority<newProcess->processPriority){//new process lower priority
         contents(processhead);
         newProcess->executionStartTime = 0;
         newProcess->executionEndTime = 0;
         newProcess->remainingBurstTime = newProcess->totalBurstTime;
         processtail->next=newProcess;
         processtail=newProcess;
         printf("new process in handle %d \n",newProcess->processID);
         printf("current process continues%d \n",currProcess->processID);
         printf("processhead in case 3 %d \n",processhead->processID);
         return currProcess;
       }

    }
    /*   printf("process id = %d \n",currProcess.processID);
       printf("arrival time = %ld \n",currProcess.arrivalTimeStamp);
       printf("total burst time = %ld \n",currProcess.totalBurstTime);
       printf("start time = %ld \n",currProcess.executionStartTime);
       printf("end time = %ld \n",currProcess.executionEndTime);
       printf("remaining burst time = %ld \n",currProcess.remainingBurstTime);
       printf("priority = %d \n",currProcess.processPriority);
*/
}
struct PCB* handleProcessCompletion_PP(struct PCB *processhead,int currTime){
       if (processhead==NULL){
          return NULL;
       }else{
       contents(processhead);
       printf("in else processhead is %d \n",processhead->processID);
       struct PCB *processtemp;
       processtemp=processhead;
       int len=length(processhead);
       struct PCB *procArray[len];
       int i=0;
       printf("test");
       while(i<len){
           procArray[i] = processtemp;
           printf("process put in array %d",procArray[i]->processID);
           processtemp=processtemp->next;
           i++;
       }
       int min =0;
       for(i=0;i<len;i++){
          if(procArray[min]->processPriority > procArray[i]->processPriority){
             min = i;
          }
       }
       printf("high priority process %d",procArray[min]->processID);
       procArray[min]->executionStartTime = currTime;
       procArray[min]->executionEndTime = currTime+procArray[min]->remainingBurstTime;
       procArray[min-1]->next=procArray[min+1];
       printf("process to run next is %d",procArray[min]->processID);
       return procArray[min];
       //return processhead;
       }
}
Hi All

I am trying to code for CPU scheduling algorithms in C using linked list...In the code snippet below Im maintaining a linked list of the processes
and processhead points to head of the list currProcess is currently running and newprocess is newly arriving..this code is for priority preemptive scheduling

The problem is as I modify the processhead to point to a different process in the function the change is effected in processhead inside the handle function however in main the value is the same as it was before the function was called.
I thought the basic purpose of pointers was to not have this problem.I might be wrong in the code as I am new to working with pointers. Please help and yeah this is my assignment and I have written the code myself.
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
  1. Don't hijack a 6 year old (or someone else's) thread.
  2. See #1.
  3. Don't point to a web site to show your code. Post it in a code block here instead.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.