Fix
This commit is contained in:
parent
81e51f0e7f
commit
0cdb352220
|
@ -1,11 +1,11 @@
|
|||
---
|
||||
title: Linux Kernel, syscalls
|
||||
date: 2022-11-19T
|
||||
date: 2023-11-11T01:22:30Z
|
||||
slug: linux-kernel-sys-fork
|
||||
description: ""
|
||||
---
|
||||
|
||||
#### sys_fork()
|
||||
### sys_fork()
|
||||
|
||||
```asm
|
||||
.align 2
|
||||
|
@ -23,7 +23,7 @@ _sys_fork:
|
|||
1: ret
|
||||
```
|
||||
|
||||
##### `FUNCTION find_empty_process()`
|
||||
#### `FUNCTION find_empty_process()`
|
||||
|
||||
```assembly
|
||||
A:
|
||||
|
@ -49,11 +49,12 @@ A:
|
|||
|
||||
|
||||
|
||||
##### `FUNCTION copy_process`
|
||||
|
||||
`<- nr, EBP, EDI, ESI, GS, EBX~EDX, CS~FS, EIP, EFLAGS, ESP, SS`
|
||||
`-> INT`
|
||||
#### `FUNCTION copy_process`
|
||||
|
||||
```
|
||||
<- nr, EBP, EDI, ESI, GS, EBX~EDX, CS~FS, EIP, EFLAGS, ESP, SS
|
||||
-> INT
|
||||
```
|
||||
|
||||
```assembly
|
||||
TASK_STRUCT P
|
||||
|
@ -117,24 +118,15 @@ RET last_pid
|
|||
|
||||
|
||||
|
||||
"nr" passed is the index of the new task in the task array, where each element corresponds to a process slot.
|
||||
|
||||
fork() copies the parent's kernel context, as well as general registers and segment selectors required for a new process to run in user space.
|
||||
|
||||
It creates a new task structure from a new free page and sets up default values and certain parameters inherited from the parent, such as process ID, priority, and execution times.
|
||||
|
||||
Then it copies memory regions from the parent to the new process, referred to by "nr," which is the index of the new process in the task array.
|
||||
|
||||
Changes the parent process's working directory (PWD) and root directory reference counters, incrementing them by 1 to reflect the new child process now also using these resources.
|
||||
|
||||
Sets the Task State Segment (TSS) and Local Descriptor Table (LDT) entries, which are x86-specific structures used for task switching and memory segmentation, respectively.
|
||||
|
||||
TSS holds information about the task's stack for privilege level changes and also the hardware context when a task switch occurs.
|
||||
|
||||
LDT is a segment descriptor table that stores descriptors for local segments, giving a task its own set of segment registers.
|
||||
|
||||
Finally, it assigns the newly created task structure, p, to the task array at index "nr." This effectively makes the new task available for scheduling.
|
||||
|
||||
|
||||
- "nr" passed is the index of the new task in the task array, where each element corresponds to a process slot.
|
||||
- fork() copies the parent's kernel context, as well as general registers and segment selectors required for a new process to run in user space.
|
||||
- It creates a new task structure from a new free page and sets up default values and certain parameters inherited from the parent, such as process ID, priority, and execution times.
|
||||
- Then it copies memory regions from the parent to the new process, referred to by "nr," which is the index of the new process in the task array.
|
||||
- Changes the parent process's working directory (PWD) and root directory reference counters, incrementing them by 1 to reflect the new child process now also using these resources.
|
||||
- Sets the Task State Segment (TSS) and Local Descriptor Table (LDT) entries, which are x86-specific structures used for task switching and memory segmentation, respectively.
|
||||
- TSS holds information about the task's stack for privilege level changes and also the hardware context when a task switch occurs.
|
||||
- LDT is a segment descriptor table that stores descriptors for local segments, giving a task its own set of segment registers.
|
||||
- Finally, it assigns the newly created task structure, p, to the task array at index "nr." This effectively makes the new task available for scheduling.
|
||||
|
||||
### `_sys_fork()`
|
||||
"sys_fork" finds an empty process ID using the search loop in `_find_empty_process`, then it invokes `_copy_process` to clone the parent's kernel context to the new process. This sets up a complete environment for the new process to run independently from the parent, but initially as a nearly identical copy.
|
|
@ -1 +1,8 @@
|
|||
ssh web /srv/blog/scripts/update.sh
|
||||
HOST=$1
|
||||
if [[ -z $1 ]];
|
||||
then
|
||||
HOST="web"
|
||||
echo $HOST
|
||||
fi
|
||||
|
||||
ssh $HOST /srv/blog/scripts/update.sh
|
||||
|
|
Loading…
Reference in New Issue