第 2 章 Linux 内核

Click here to load reader

download 第 2 章   Linux 内核

of 69

description

第 2 章 Linux 内核. —— 进程管理. 本章主要介绍: 进程概念 进程的组成 进程的状态和调度 进程间关系 中断处理与定时器 系统调用 进程间通信. 1 进程概念. 20 世纪 60 年代,进程 (process) 一词首先在麻省理工学院的 MULTICS 和 IBM 的 CTSS/360 系统中被引入。 对进程下个准确定义不容易,但有必要强调一下进程具有的两个重要特性。. 1. 独立性. 进程 是系统中独立存在的实体,它可以拥有自己独立的资源,比如文件和设备描述符等。 - PowerPoint PPT Presentation

Transcript of 第 2 章 Linux 内核

  • 2 Linux

  • 1 2060(process)MULTICSIBMCTSS/360

  • 1.

  • 2.

  • (concurrency)(parallel)

  • 2

  • LinuxPID(process ID) PID UID GID

  • UIDGID4 UIDuideuidsuidfsuid GIDgidegidsgidfsgid uid=euid=fsuidgid=egid=fsgid

  • uidgideuidegiduidgidsuidsgidfsuidfsgid

  • (context)LinuxPCB(process control block)(text segment)(data segment)(stack)

  • (process table)PCB2-1

  • 2-1

  • PIDPCB(PIDhash)PCB

  • 3

  • LinuxLinux29killkillpg

  • 3-1

  • 3-1 Linux

  • 3

  • (ready)

  • (blocked)

  • task_structPIDinclude/Linux/sched.h

  • task_struct (include/linux/sch.h)

  • task_struct state Linux5:

  • 2-2 Linux

  • RUNNING RUNNING

  • Linux

  • UNINTERRUPTABLE

  • INTERRUPTABLE

  • STOPPED (SIGSTOPSIGSTPSIGTTIN SIGTTOU) ptrace

  • ZOMBIE

  • (scheduler) Linuxschedule() schedule()C

  • fork()do_fork()fork fork() PID

  • fork()RUNNING RUNNINGschedule()

  • sleep()PCB sleep()schedule().

  • RUNNING

  • exit()SIG_KILLZOMBIE schedule()

  • STOPPED SIG_KILLSIG_CONTSTOPPED

  • PCB (FIFO)(round-robin)(Linux)

  • Linux(10ms) schedule()goodness() Linux

  • 4 Linux0ABABBA

  • task_struct struct task_struct *p_pptr, *p_cptr, *p_ysptr, *p_osptr;p_pptr: parent ()p_cptr: child ()p_ysptrp_osptr

  • PCBp_cptrPCBPCBp_pptrPCB 2-3

  • 2-3

  • task[]task_structPid hashpidhashrun_listprio_array

  • currentcurrentinittask_struct: INIT_TASK

  • start_kernel()0init_task()0 0

  • fork()fork Linuxfork() Afork()Bfork()AB Afork()PIDBfork()0fork()

  • fork()? fork() PCB .forkfork.swf

  • PCBPCB

  • vfork()SIG_STOP

  • fork() Linuxfork+exec execve() execve()

  • 5

  • Linux 1. POSIX

  • () Linux

  • 2. (FIFO) LinuxFIFO(named pipe)

  • FIFOfirst infirst out FIFO FIFOread()write()

  • 3. IPC IPCinterprocess communication . IPCColumbus UnixUnix

  • IPC

  • (1)

  • (2)

  • (3) IPC

  • 0101 0 25

  • 11

  • IPC IPC

  • 6 Linux ()

  • ABx1

  • 1 Linux

    , ,CPU (,)

    1. 2. euidegiduidgid euidegid uideuidgidegidrootuidgideuidegid 3 suidsgidPOSIXuidgiduidgid 4. fsuidfsgiduidgidLINUX euidegidNFSNFSfsuidfsgid:;;PCBPCBp_osptr PCBPCBp_ysptrPCB p_cptrforkforkLinux fork()fork()PID fork()fork()fork()PIDfork()0

    ( ) 001

    ABCPUx2 ABx1 x1