Process scheduling :

When creating a process , Initialization of process scheduling class in function sched_init() conduct
void sched_init(void) { int i; struct desc_struct * p; if (sizeof(struct
sigaction) != 16) panic("Struct sigaction MUST be 16 bytes"); // Set local state of kernel
Descriptors and program status segments set_tss_desc(gdt+FIRST_TSS_ENTRY,&(init_task.task.tss));
set_ldt_desc(gdt+FIRST_LDT_ENTRY,&(init_task.task.ldt)); // Offset p =
gdt+2+FIRST_TSS_ENTRY; // Clear the entire global task struct Structure pointer array for(i=1;i<NR_TASKS;i++) {
task[i] = NULL; // empty task list // empty GDT p->a=p->b=0; p++; p->a=p->b=0; p++; } /*
Clear NT, so that we won't have troubles with that later on */ __asm__("pushfl
; andl $0xffffbfff,(%esp) ; popfl"); // set up cms ltr(0); lldt(0);
outb_p(0x36,0x43); /* binary, mode 3, LSB/MSB, ch 0 */ outb_p(LATCH & 0xff ,
0x40); /* LSB */ outb(LATCH >> 8 , 0x40); /* MSB */ // Turn on system clock interrupt
set_intr_gate(0x20,&timer_interrupt); outb(inb_p(0x21)&~0x01,0x21); // Turn on system call
Set interrupt function set_system_gate(0x80,&system_call); }

It is equivalent to treating a process as a linked list node .

Process creation :

* First we create 0 Process ,0 Process is the parent of all processes .(main.c/init())               
void init(void) { int pid,i; // function setup.s program , Configure // Get by setup Parameters for program parsing
setup((void *) &drive_info); //open File handle for standard input (void) open("/dev/tty0",O_RDWR,0);
// Open the standard input console (void) dup(0); // Open the standard output console (void) dup(0); // Open standard error console //make
mkdir("/proc",755); mknod("/proc/sysinfo", S_IFPROC,8 ); printf("%d buffers =
%d bytes buffer space\n\r",NR_BUFFERS, NR_BUFFERS*BLOCK_SIZE); printf("Free
mem: %d bytes\n\r",memory_end-main_memory_start); // establish 1 Process if (!(pid=fork())) {
close(0); if (open("/etc/rc",O_RDONLY,0)) _exit(1);
execve("/bin/sh",argv_rc,envp_rc); _exit(2); }
   init() Function overview :

            1. Open standard input output Bad console handle

            2. establish 1 Process , If created successfully , First opened in process 1   "/etc/rc" file ( configuration file ) implement SHELL program "/bin/sh"

    be careful :0 It's impossible for process to end , It will be called when there is no other process , Execute only for(;;) pause();

* stay tack Find a process space in the linked list to store the current process   (fork.c) , Return a process number
int find_empty_process(void) { int i; repeat: if ((++last_pid)<0) last_pid=1;
for(i=0 ; i<NR_TASKS ; i++) if (task[i] && task[i]->pid == last_pid) goto
repeat; for(i=1 ; i<NR_TASKS ; i++) if (!task[i]) return i; return -EAGAIN; }
* Create a subprocess's task_struct structural morphology
// by task_struct Allocate a piece of memory p = (struct task_struct *) get_free_page(); if (!p)
return -EAGAIN;
* Put the current subprocess into the overall process list

         task[nr] = p;

* Set current task_struct structural morphology // Settings assigned and added to global task In array task_struct p->state =
TASK_UNINTERRUPTIBLE; p->pid = last_pid; p->father = current->pid; p->counter =
p->priority; p->signal = 0; p->alarm = 0; p->leader = 0; /* process leadership
doesn't inherit */ p->utime = p->stime = 0; p->cutime = p->cstime = 0;
p->start_time = jiffies; // set up TSS paragraph , Program runtime CPU Value of register in p->tss.back_link = 0;
p->tss.esp0 = PAGE_SIZE + (long) p; p->tss.ss0 = 0x10; p->tss.eip = eip;
p->tss.eflags = eflags; p->tss.eax = 0; p->tss.ecx = ecx; p->tss.edx = edx;
p->tss.ebx = ebx; p->tss.esp = esp; p->tss.ebp = ebp; p->tss.esi = esi;
p->tss.edi = edi; p->tss.es = es & 0xffff; p->tss.cs = cs & 0xffff; p->tss.ss =
ss & 0xffff; p->tss.ds = ds & 0xffff; p->tss.fs = fs & 0xffff; p->tss.gs = gs &
0xffff; p->tss.ldt = _LDT(nr); p->tss.trace_bitmap = 0x80000000;
// Set whether the current process uses coprocessor if (last_task_used_math == current) __asm__("clts ; fnsave
%0"::"m" (p->tss.i387));  For a process, we can think of it as three parts

              

task_struct Detailed introduction of structure :
long state; // Status of process running TASK_RUNNING        0 Operation state TASK_INTERRUPTIBLE    1 Interruptible state
TASK_UNINTERRUPTIBLE    2 Non interruptible state TASK_ZOMBIE        3 Zombie state TASK_STOPPED      
 4 Stop state  long counter;// Execution time slice of process , Indicates that the current process can occupy CPU Time of resource long priority;// Process priority long
signal; // Semaphore bitmap 32bit every last bit To represent a signal struct sigaction sigaction[32];// Semaphore long
blocked; /* bitmap of masked signals */ // Signal mask /* various fields */ int
exit_code; // Exit code unsigned long start_code,end_code,end_data,brk,start_stack;
// Memory usage information for the current process long pid,father,pgrp,session,leader;//father pid unsigned short
uid,euid,suid;// Users of the process ID Process effectiveness ID Process super ID unsigned short gid,egid,sgid;// Group of processes ID
Valid groups for the process ID Supergroup of processes ID long alarm; // Warning flags for processes long
utime,stime,cutime,cstime,start_time;// User time for the process system time Current user time Current system time start time
unsigned short used_math;// Use coprocessor or or not /* file system info */ int tty; /* -1 if no
tty, so it must be signed */// Whether the current process occupies the console unsigned short umask; // User's mask struct
m_inode * pwd; // route struct m_inode * root; // root directory struct m_inode *
executable;// Execution bitmap unsigned long close_on_exec;// Close bitmap after execution struct file *
filp[NR_OPEN];// File table for the current process FD Find one in this array file structural morphology /* ldt for this task 0 - zero 1 -
cs 2 - ds&ss */ struct desc_struct ldt[3]; // The local descriptor table consists of code segments and data segments /* tss for this
task */ struct tss_struct tss; // Program status segment

Technology
©2019-2020 Toolsou All rights reserved,
【Python- data fetch 】 read txt Each line of file generates a list of data java Compile time and runtime exceptions in Output string at specified position ( Detailed analysis ) Maximum security risk of cloud computing : Unclear safety responsibility el-ui:select Get value elementui select obtain valueSSM Project's excel File upload and add to database airflow Question series 2 —— task keep running Suspended animation be based on RK3399 PWM Drive development el-select At the same time label and value value