Huawei machine questions-Operating System Task Scheduling

Source: Internet
Author: User
[Problem]

Task Scheduling in the operating system. Operating system tasks are classified into system tasks and user tasks. The system task priority is <50, the user task priority is> = 50, and <= 255. An invalid task with a priority greater than 255 should be excluded. The existing task queue task [] has a length of n. The element value in the task indicates the priority of the task. The smaller the value, the higher the priority. The scheduler function implements the following functions, store the tasks in task [] to the system_task [] array and the user_task [] array in sequence by system tasks and user tasks (the element value in the array is the subscript of the task in the task [] array ). ), in addition, tasks with a higher priority are listed first, and tasks with the same priority are arranged in the queue Order (that is, tasks with the same priority are listed first). The array element is-1, indicating the end of the task.

Example: task [] = {0, 30,155, 1, 80,300,170, 40, 99} system_task [] = {0, 3, 1, 7, -1} user_task [] = {4, 8, 2, 6,-1}

Function interface void scheduler (INT task [], int N, int system_task [], int user_task [])

[Code]
# Include <stdio. h> # include <stdlib. h> # include <string. h> typedef struct node {int priority; int index;} tasknode; void schedity (INT task [], int N, int system_task [], int user_task []) {int I, j, k; tasknode * tasklist; tasknode TMP; tasklist = (tasknode *) malloc (N * sizeof (tasknode); for (I = 0; I <N; I ++) {tasklist [I]. priority = task [I]; tasklist [I]. index = I ;}// stable sorting for (I = 0; I <n-1; I ++) for (j = I + 1; j <n; j ++) if (tasklist [I]. priority> tasklist [J]. priority) {TMP = tasklist [I]; tasklist [I] = tasklist [J]; tasklist [J] = TMP;} // Category J = k = 0; for (I = 0; I <n; I ++) {If (tasklist [I]. priority <50) system_task [J ++] = tasklist [I]. index; else if (tasklist [I]. priority> = 50 & tasklist [I]. priority <= 255) user_task [k ++] = tasklist [I]. index;} system_task [J] =-1; user_task [k] =-1; for (I = 0; I <= J; I ++) printf ("% d", system_task [I]); printf ("\ n"); for (I = 0; I <= K; I ++) printf ("% d", user_task [I]); printf ("\ n"); free (tasklist);} int main (void) {int task [] = {0, 30,155, 1, 80,300,170, 40, 99}; int system_task [10]; int user_task [10]; scheduler (task, 9, system_task, user_task); Return 0 ;}


Huawei machine questions-Operating System Task Scheduling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.