Code/Loadbalancer_v2.c
void initialize_process_info(struct process *p,int processors)
{
  FILE *outputfile,*fp;
  char var[80];
  // Opens the file to read the contents and store the process information
  fp = fopen("process_info.txt","r");       
  if(fp == NULL)
  { 
    printf("Error in opening file!!");
    exit(0);
  }
  else
  {  
    char s[80];
    int i =0,k=0,id=0,c=0;
    fgets(s,80,fp);
    // Iterates through each line to get the process_id of all running processes
    while(fgets(s,80,fp))                
    {  
        while(s[k]==' ') { k++; }
        /*
        process_id starts from third character in each line 
        (Default postion in the file)
        */
        for(int j=k;s[j]!=' ';j++)        
        {
          id*=10;
          id+= s[j]-'0';                   // Converts char to int
          k=j; // Keeps track of the last index in which the process_id exists                            
        }
        
        p[i].process_id = id;      // Assigns the process_id for the processes
        id=0;
        k+=10;
        
        while(s[k]==' '){  k++; }         // Iterates through the white spaces
        
        while(s[k]!='.')
        {
          c*=10;
          c+=s[k]-'0';
          k++;
        }
        // Includes the decimal point
        k++;
        c*=10;
        c+=s[k]-'0';
        // Assigns the CPU Utilization of the core the process runs on 
        p[i].cpu_util = c/10.0;           
        // Iterates to the end of line to get the core_id of that  process
        while(s[k]!='\n'){  k++; }        
        p[i].core_id = s[k-1]-'0';        // Assigns the core_id for the process
        i++;               // Increments i to store the next Process information
        k=0;
        c=0;       // Initializes the cpu utilization count for the next process
    }
  }
  fclose(fp);
}
/*
	Function name : initialize_process_info() 
	Purpose       : To initialize the process information of all the currently 
                  running processes
	Inputs        : Structure array address, number of cores
	Output        : Process information of all the processes are stored in the 
                  respective structures
*/
Function name : initialize_process_info()
Purpose       : To initialize the process information of all the currently
running processes
Inputs        : Structure array address, number of cores
Output        : Process information of all the processes are stored in the
respective structures
Function name : initialize_process_info () Purpose : To initialize the process information of all the currently running processes Inputs : Structure array address number of cores Output : Process information of all the processes are stored in the respective structures
void initialize_process_info(struct process *p,int processors)
{
  FILE *outputfile,*fp;
  char var[80];
  fp = fopen("process_info.txt","r");       
  if(fp == NULL)
  { 
    printf("Error in opening file!!");
    exit(0);
  }
  else
  {  
    char s[80];
    int i =0,k=0,id=0,c=0;
    fgets(s,80,fp);
    while(fgets(s,80,fp))                
    {  
        while(s[k]==' ') { k++; }
        for(int j=k;s[j]!=' ';j++)        
        {
          id*=10;
          id+= s[j]-'0';                   
          k=j; 
        }
        p[i].process_id = id;      
        id=0;
        k+=10;
        while(s[k]==' '){  k++; }         
        while(s[k]!='.')
        {
          c*=10;
          c+=s[k]-'0';
          k++;
        }
        k++;
        c*=10;
        c+=s[k]-'0';
        p[i].cpu_util = c/10.0;           
        while(s[k]!='\n'){  k++; }        
        p[i].core_id = s[k-1]-'0';        
        i++;               
        k=0;
        c=0;       
    }
  }
  fclose(fp);
}
void initialize_process_info ( struct process * p , int processors ) { FILE * outputfile , * fp ; char var [ 80 ] ; fp = fopen ( " " , " " ) ; if ( fp == NULL ) { printf ( " " ) ; exit ( 0 ) ; } else { char s [ 80 ] ; int i = 0 , k = 0 , id = 0 , c = 0 ; fgets ( s , 80 , fp ) ; while ( fgets ( s , 80 , fp ) ) { while ( s [ k ] == ' ' ) { k ++ ; } for ( int j = k ; s [ j ] != ' ' ; j ++ ) { id *= 10 ; id += s [ j ] - ' ' ; k = j ; } p [ i ] . process_id = id ; id = 0 ; k += 10 ; while ( s [ k ] == ' ' ) { k ++ ; } while ( s [ k ] != ' ' ) { c *= 10 ; c += s [ k ] - ' ' ; k ++ ; } k ++ ; c *= 10 ; c += s [ k ] - ' ' ; p [ i ] . cpu_util = c / 10.0 ; while ( s [ k ] != ' \n ' ) { k ++ ; } p [ i ] . core_id = s [ k - 1 ] - ' ' ; i ++ ; k = 0 ; c = 0 ; } } fclose ( fp ) ; }
Function name : initialize_process_info()
Purpose       : To initialize the process information of all the currently
running processes
Inputs        : Structure array address, number of cores
Output        : Process information of all the processes are stored in the
respective structures
Function name : initialize_process_info () Purpose : To initialize the process information of all the currently running processes Inputs : Structure array address number of cores Output : Process information of all the processes are stored in the respective structures
// Opens the file to read the contents and store the process information // Iterates through each line to get the process_id of all running processes /*
        process_id starts from third character in each line 
        (Default postion in the file)
        */ // Converts char to int // Keeps track of the last index in which the process_id exists                             // Assigns the process_id for the processes // Iterates through the white spaces // Includes the decimal point // Assigns the CPU Utilization of the core the process runs on  // Iterates to the end of line to get the core_id of that  process // Assigns the core_id for the process // Increments i to store the next Process information // Initializes the cpu utilization count for the next process