| |

VerySource

 Forgot password?
 Register
Search
View: 839|Reply: 5

Help write a program that prioritizes short jobs for process scheduling in the operating system, thanks!

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-3 10:00:02
| Show all posts |Read mode
Help write a program that prioritizes short jobs for process scheduling in the operating system, thanks!
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-3 11:36:01
| Show all posts
Can anyone help me?
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-3 16:06:01
| Show all posts
Any book on operating system in C language has the program code, assignment questions and appraisal after you want it.
Reply

Use magic Report

0

Threads

19

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-3 21:33:01
| Show all posts
The complete code (C language):
  #include <stdio.h>
  #include <malloc.h>
    
  int FIND (int * parent, int i)
  {// Find the root of the tree containing element i, and use compression rules to compress all nodes from i to root j
  int j, k, t;
  j = i;
  while (parent [j]> 0) j = parent [j]; // Find the root
  k = i;
  while (k! = j) {// compress the node from i to root j
  t = parent [k];
  parent [k] = j;
  k = t;
  }
  return j;
  }
    
  void UNION (int * parent, int i, int j)
  {// Merge two sets of roots i and j using weighting rules
  int x;
  x = parent [i] + parent [j];
  if (parent [i]> parent [j]) {// i has fewer nodes
  parent [i] = j;
  parent [j] = x;
  }
  else {// j has fewer nodes
  parent [j] = i;
  parent [i] = x;
  }
  }
    
  int MIN (int n, int m)
  {// Find the minimum of n and m
  if (n> m) return m;
  else return n;
  }
    
  int FJS (int * D, int n, int b, int * J, int * Q)
  {// Find the optimal solution of J (n), and return the number of optimal solutions
  int i, * F, * p, j, l, m, k;
  F = (int *) malloc ((b + 1) * sizeof (int));
  p = (int *) malloc ((b + 1) * sizeof (int));
          for (i = 0; i <= b; i ++) {// set the tree to its initial value
  F [i] = i;
  p [i] =-1;
  }
  k = 0; // initialize J
  for (i = 1; i <= n; i ++)
  {// Use greedy rules
  j = FIND (p, MIN (n, D [i]));
  if (F [j]! = 0)
  {// Choose job i
  k = k + 1;
  J [k] = i;
          Q [F [j]] = i;
  m = F [j];
  l = FIND (p, F [j] -1);
  UNION (p, l, j);
  F [j] = F [l];
  }
  }
  return k; // Return the number of optimal solutions
  }
    
    
  int MAXMUM (int i, int j)
  {// Find the maximum of i and j
  if (i> j) return i;
  else return j;
  }
    
  int MAX (int * D, int i, int j)
  {// D (1: n) is an array of n elements, find the maximum value in D (i, j) and return
  int max, mid, max1, max2;
  if (i == j) max = D [i];
          else
  if (i == j-1)
  if (D [i] <D [j]) max = D [j];
  else max = D [i];
  else {
  mid = (i + j) / 2;
  max1 = MAX (D, i, mid);
  max2 = MAX (D, mid + 1, j);
  max = MAXMUM (max1, max2);
  }
  return max;
  }
    
  void Insertionsort (int * D, int n)
  {// Classify the elements in D in non-increasing order
  int j, item, i;
  D [0] = 65525; // Set watchpoint
  for (j = 2; j <= n; j ++) {
  item = D [j];
  i = j-1;
  while (item> D [i]) {
  D [i + 1] = D [i];
  i = i-1;
  }
  D [i + 1] = item;
    
  }
    
  }
    
  void main ()
  {
  int * D, * J, * Q, * p, n, b, i, k;
                  printf ("\n ******************* Use greedy method to solve the problem of job sequencing with a finite period of time ********\n ");
  printf ("\n Please enter the number of jobs:\n");
  scanf ("% d",&n);
  D = (int *) malloc ((n + 1) * sizeof (int));
  p = (int *) malloc ((n + 1) * sizeof (int));
          printf ("\n Please enter the benefit value of each job (% d):", n);
  for (i = 1; i <= n; i ++)
  scanf ("% d",&p [i]);
  Insertionsort (p, n);
  printf ("\n each job after non-increasing order by benefit value:\n");
          printf ("\n job serial number benefit value\n");
          for (i = 1; i <= n; i ++)
  printf ("J% d% d\n", i, p [i]);
  printf ("\n");
  printf ("\n, please enter the deadline for each job after non-increasing order of benefits (% d):", n);
  for (i = 1; i <= n; i ++)
  scanf ("% d",&D [i]);
  b = MIN (n, MAX (D, 1, n));
          J = (int *) malloc ((b + 1) * sizeof (int));
  Q = (int *) malloc ((b + 1) * sizeof (int));
          for (i = 1; i <= b; i ++)
  Q [i] =-1;
  k = FJS (D, n, b, J, Q);
  printf ("\n\n ************************ The optimal solution for this problem **************** *************\n\n ");
          printf ("\n job serial number benefit value\n");
          for (i = 1; i <= k; i ++)
  printf ("J% d% d\n", J [i], p [i]);
  printf ("\n\n ************************ The execution order of each job ***************** *************\n ");
  printf ("\n job serial number benefit value\n");
          for (i = 1; i <= b; i ++)
  if (Q [i]! =-1)
              printf ("J% d% d\n", Q [i], p [i]);
  printf ("\n\n");
    
  }
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-4 17:39:01
| Show all posts
thank! !! !! But there are some places in the program that are not very clear and need to be considered again.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 12:00:01
| Show all posts
Learn from the master!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list