Linux ??????????? - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Linux ???????????

Description:

– PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 36
Provided by: edut1550
Category:
Tags: linux

less

Transcript and Presenter's Notes

Title: Linux ???????????


1
????
  • ??? ??????

2
??? ??????
  • ????
  • ?????
  • ????
  • ????
  • ????
  • ????
  • ??????
  • ??

3
????
  • ????????????,????????????????
  • Linux ???????????
  • ??????
  • ????
  • ????
  • ????

4
?????
  • ???????????,???????
  • ?????????????????????
  • ???????????????????????
  • Linux ???????? task_struct???? Linux
    ?????include/linux/sched.h ??

5
????
  • ? Linux ?,??????????????? state ??

volatile long state / -1 ????,0 ???,gt0 ??? /
define TASK_RUNNING 0 define
TASK_INTERRUPTIBLE 1 define TASK_UNINTERRUPTIBLE
2 define TASK_ZOMBIE 4 define
TASK_STOPPED 8
6
???? (?)
  • TASK_RUNNING???????????????
  • TASK_INTERRUPTIBLE?????????,?????????
  • TASK_UNINTERRUPTIBLE?TASK_INTERRUPTIBLE
    ??,????????????????????
  • TASK_STOPPED?? SIGSTOP?SIGTSTP?SIGTTIN ?SIGTTOU
    ????
  • TASK_ZOMBIE???????,????????? wait()
    ????????????????????,??????????????

7
????
  • Linux ????????????? PCB ?????
  • ??????? next_task ? prev_task ?????,??????????
  • ??for_each_task ????????????????

struct task_struct next_task, prev_task
8
Linux ?????
9
????
  • ???????????,?????TASK_RUNNING?
  • ????????????? run_list ??
  • ???????

struct list_head run_list
static LIST_HEAD(runqueue_head)
10
???? (?)
  • ???????????
  • add_to_runqueue()

static inline void add_to_runqueue(struct task_struct p) list_add(p-gtrun_list, runqueue_head) nr_running
11
??? ??????
  • ????
  • ????
  • ????
  • ????
  • ????
  • ??????
  • ??

12
????
  • ???????,????????????????
  • Linux ?????
  • ??
  • ????
  • ??

13
????
  • ????????????
  • fork()
  • vfork()
  • clone()
  • fork() ???????????????
  • copy-on-write ??
  • vfork() ??????????????????
  • ????? vfork() ?????

14
???? (?)
  • clone() ???????????????????????????????
  • ???? fork()? vfork() ? clone() ????????
    do_fork()?
  • ? vfork() ??

asmlinkage int sys_vfork(struct pt_regs regs) return do_fork(CLONE_VFORK CLONE_VM SIGCHLD, regs.esp, regs, 0)
15
???? (?)
  • do_fork() ????????????? 6 ???,???
  • ?? task_struct ????
  • ????? task_struct ???????
  • ????? task_struct ???????????????????
  • ?? clone_flags ????????????,??????????????
  • ????? task_struct ???????????
  • ???????

16
????
  • ?????,????????????? CPU ?????????
  • ????????????,??????????????
  • Linux ?????????? switch_to ????????

17
??? CPU ?????????(1)
??prev??????
ESP
0x1d001d00
stack
esp0x1f002100
ESI
0x1c100100
data
eip0x1b01c000
text
??prev
EDI
0x1c001100
??next??????
stack
EIP
0x1b00a100
data
esp0x1a00c100
CPU???
text
??next
eip0x1a00a000
????
18
??? CPU ?????????(2)
??prev??????
ESP
0x1d001d00
stack
esp0x1d001d00
data
ESI
0x1c100100
eip0x1b01c000
text
??prev
EDI
0x1c001100
??next??????
stack
EIP
0x1b00a104
data
esp0x1a00c100
CPU???
text
??next
eip0x1a00a000
????
19
??? CPU ?????????(3)
??prev??????
ESP
0x1a00c100
stack
esp0x1d001d00
data
ESI
0x1c100100
eip0x1b01c000
text
??prev
EDI
0x1c001100
??next??????
stack
EIP
0x1b00a108
data
esp0x1a00c100
CPU???
text
??next
eip0x1a00a000
????
20
??? CPU ?????????(4)
??prev??????
ESP
0x1a00c100
stack
esp0x1d001d00
data
ESI
0x1c100100
eip0x1d001d18
text
??prev
EDI
0x1c001100
??next??????
stack
EIP
0x1b00a10c
data
esp0x1a00c100
CPU???
text
??next
eip0x1a00a000
????
21
??? CPU ?????????(5)
??prev??????
ESP
0x1a00c100
stack
esp0x1d001d00
data
ESI
0x1c100100
eip0x1d001d18
text
??prev
EDI
0x1c001100
??next??????
stack
EIP
0x1a00a000
data
esp0x1a00c100
CPU???
text
??next
eip0x1a00a000
????
22
??? CPU ?????????(6)
??prev??????
ESP
0x1a00c100
stack
esp0x1d001d00
data
ESI
0x1c100100
eip0x1d001d18
text
??prev
EDI
0x1c001100
??next??????
stack
EIP
0x1a00a00c
data
esp0x1a00c100
CPU???
text
??next
eip0x1a00a000
????
23
????
  • ??????????????????????
  • ????????????????????
  • ??????,??????????????? exit() ?????
  • ??????????? do_exit() ???

24
???? (?)
  • do_exit() ???????????
  • ???????? flag ???? PF_EXITING,???????????
  • ??????????????????????????
  • ?????????????????????????????????
  • ???????? state ? exit_code ?????? TASK_ZOMBIE
    ????????
  • ????????????????
  • ????? schedule() ?????????????

25
??? ??????
  • ????
  • ????
  • ??????
  • ???
  • ??
  • ????
  • ??

26
??????
  • Linux ????????????,????????
  • ??
  • ??
  • ??
  • ?????
  • ??
  • Linux ????????????,????????????????,?????????,?
  • ???
  • ??

27
???
  • ??????????,???????,??????,??????????????
  • ?????????,????????????????,???????????????????,???
    ??
  • ?????????????????

28
??? (?)
  • ?????? spinlock_t ?????,?????? lock ??
  • lock ??? 1 ?,????????
  • lock ?????? 0 ?,?????????
  • spin_lock() ? spinlock_t ???? lock ???? 1,?? lock
    ???? 0,?????????? lock ??????? 0?
  • spin_unlock() ? lock ?????? 1?
  • ???????????????,?????????????
  • ? / ??????

29
? / ????
???
R
R
R
W
???
W
?? B
?? A
???
W
R
W
?? F
?? D
???
30
??
  • Linux ????????????????
  • Linux ???????? struct semaphore?
  • struct semaphore ??? count
  • ?? 0 ?,????????????
  • ????? 0 ?,?????????????
  • ???????
  • down() - ???? count ?? 1?
  • up() - ? count ?? 1?

31
????
  • ???????????????? IPC ????
  • ??????? IPC ???
  • semget()?msgget() ? shmget() ???????????????? IPC
    ???
  • Linux ???? IPC ????????? ipc() ?????????
  • ????
  • msgget() - ??????????
  • msgsnd() - ?????
  • msgrcv() - ?????

32
???? (?)
  • Linux IPC ?????????
  • struct ipc_ids - ??? IPC ???????? ipc_ids
    ??,????? msg_ids?
  • struct msg_queue - ?????????
  • struct msg_msg?struct msg_msgseg - struct msg_msg
    ????????,??????????????????????????(4 KB)?,?????
    struct msg_msgseg ????
  • struct msg_sender?struct msg_receiver -
    ???????????????????
  • msgsnd() ??????? sys_msgsnd(),?????????,???
  • ????
  • ????????????????
  • ??????????????????????????

33
IPC ?????????
msg_ids
msg_msg

7


m_list
msg_msg
entries

m_list

next

q_messages
next
msg_msgseg
q_senders
msg_receiver
next
msg_sender
q_receivers
r_list
list
msg_queue
r_tsk
tsk

r_msg
34
?? (1)
  • Linux ?????????????? task_struct ??????
  • Linux ??????????????
  • fork()
  • vfork()
  • clone()
  • Linux ????????????
  • switch_to

35
?? (2)
  • Linux ????????
  • ??? / ?????
  • ??
  • down() - ?????
  • up() - ?????
  • Linux ?? IPC ??,????????????????????
  • Linux ????????
  • msgget() - ??????????
  • msgsnd() - ?????
  • msgrcv() - ?????
Write a Comment
User Comments (0)
About PowerShow.com