-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux.tex
64 lines (56 loc) · 2.95 KB
/
linux.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xeCJK}
\usepackage{float}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{footmisc}
\usepackage{biblatex}
\addbibresource{bib.bib}
\date{\today}
\title{Linux}
\begin{document}
\lstset{
breaklines=true,
basicstyle=\ttfamily}
\title{OS Case Study}
\maketitle
\tableofcontents
\newpage
\section{Process Management}
\lstinline{struct task_struct}\footnote{Defined in \lstinline{include/linux/sched.h}.\label{sched.h}} is the Process Control Block (PCB) in the Linux kernel.
It stores the identifiers of a process, its current state, pointers to data structures related to the context of process, scheduling information and information about the resources associated with the process.
All process-related operations either directly or indirectly read or modify the PCB to achieve their goals.
These are some of the states that a process might be in\footref{sched.h} :
\begin{itemize}
\item \lstinline{TASK_NEW}.
When a process is first created, its state is set to \lstinline{TASK_NEW}, indicating that the process has been created but not yet started.
\item \lstinline{TASK_DEAD}.
The process has terminated.
\item \lstinline{TASK_RUNNING}.
\item \lstinline{TASK_INTERRUPTIBLE} or \lstinline{TASK_UNINTERRUPTIBLE}.
The processes in these two states are waiting for something to wake them up, but signals can only interrupt the processes marked \lstinline{TASK_INTERRUPTIBLE}.
\item \lstinline{TASK_WAKING}.
This indicates that the process has already been asked to wake up, but not yet added to the run queue. \footnote{\url{https://lore.kernel.org/lkml/[email protected]/}}
\item \lstinline{TASK_NOLOAD}.
Like \lstinline{TASK_UNINTERUPTIBLE} but processes marked with this do not count when calculating loadavg.\footnote{\url{https://lore.kernel.org/lkml/[email protected]/T/}}
\item \lstinline{TASK_WAKEKILL}.
Will wake up when received a SIGKILL.
\item \lstinline{TASK_TRACED}.
The process has been stopped by a debugger to trace its execution.
\end{itemize}
These states encoded as a bitmask are used to manipulate the \lstinline{unsigned int __state} field of \lstinline{task_struct}, therefore to identify a process' state, the scheduling code checks whether \lstinline{(t->__state & TASK_SOMESTATE)} equals 0 or uses similar logic.
Combining some of these states gives several more convenient masks, making state-related code more concise.
Scheduling information is also included in the PCB, including priority of the process, schedule entity that represents the process and a pointer to the schedule class that this process is using.
\printbibliography[heading=bibintoc]
\newpage
\end{document}