Download ppt - 第 2 章 Linux 内核

Transcript
  • 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