Presentation is loading. Please wait.

Presentation is loading. Please wait.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Unix system calls (part 1) history and.

Similar presentations


Presentation on theme: "This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Unix system calls (part 1) history and."— Presentation transcript:

1 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Unix system calls (part 1) history and usage of Python basic data types and the type hierarchy syntax modules and variable scopes

2 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Unix system calls (part 1)

3 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. This is one part of a larger series. You may need to view previous parts to understand this material.

4 It’s a Unix system!

5 System V BSD 1980’s

6 Linux Mac OS X FreeBSD, OpenBSD today

7 POSIX (Portable Operating System Interface for Unix) SUS (Single Unix Specification)

8 Process C Process B kernel Process A jump to system call code via special instruction RAM

9 0x system call 0 0x system call 1 0x system call 2 0xA system call 3 0xFF system call 4 0xFF system call 5 0xFF system call 6 0xFF system call 7 ……

10 stack code heap kernel code  pages only accessible in system calls jump to system call code via special instruction

11 frame of main frame of cat frame of dog frame of fish stack space frame of syscall

12 created waitingrunning blocked terminated

13 processes files networking sockets signals inter-process communication terminals threads I/O devices

14 ssize_t read(int fd, void *buf, size_t count);

15 read(fd)

16 process: address space user ids file descriptors environment current and root directory stack heap code heap

17 stack code initialized data heap kernel code uninitialized data  global variables with initial values  global variables without initial values

18 stack code initialized data heap kernel code uninitialized data  a.k.a. the “text”  global variables with initial values  global variables without initial values  starts empty, grows automatically  explicitly allocated during execution

19 mmap (‘memory map’ pages to the process address space) munmap (‘memory unmap’ pages from the process address space)

20 mmap (‘memory map’ pages to the process address space) munmap (‘memory unmap’ pages from the process address space) address = mmap(5000) … # do stuff with memory at address munmap(address)

21 stack code initialized data heap kernel code uninitialized data heap mmap fails when not enough space

22

23 if fork() == 0: … // new (child) process else: … // original (parent) process

24 RAM byte 0 byte n HD stack heap code heap fork

25 stack heap code heap RAM byte 0 byte n HD stack heap code heap fork

26 stack heap code heap RAM byte 0 byte n HD stack heap code heap fork

27 stack heap code heap RAM byte 0 byte n HD stack heap code heap write  fork

28 stack heap code heap RAM byte 0 byte n HD stack heap code heap copy write  fork

29 stack heap code heap exec

30 code exec (executable)

31 if fork() == 0: // new (child) process exec(‘/games/pong’) else: … // original (parent) process

32 pid 1 (init) pid 85 pid 17 pid 24pid 230 pid 104 pid 34 pid 50

33 _exit (terminate the process) _exit(0)

34 wait (block the process until child process terminates) pid = fork() if pid == 0: // new (child) process exec(‘/games/pong’) else: // original (parent) process code = wait(pid)

35 TERM=xterm SHELL=/bin/bash USER=greys MAIL=/var/mail/ted PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin PWD=/home/ted EDITOR=vim name=value

36 pid 1 (init), user 0 pid 85, user 8 pid 17, user 4 pid 24, user 33pid 230, user 8 pid 104, user 33 pid 34, user 4 pid 50, user 4

37 user accounts: /etc/passwd

38 user accounts: /etc/passwd superuser/root = user id 0 privileged to do anything it wants

39 each process has three user ids: each file and directory is owned by a single user “real” id: the owning user “effective” id: determines privileges “saved” id: set by exec to match the effective id

40 exec (sets effective and saved ids when binary file has setuid bit)

41 seteuid (sets effective user id) setuid (sets real, effective, and saved user ids)

42 exec (sets effective and saved ids when binary file has setuid bit) seteuid (sets effective user id) setuid (sets real, effective, and saved user ids) non-superuser can only directly set effective id to match the real or saved id

43 pid 1 (init), user 0 pid 3 (shell), user 1780 pid 2 (login), user 0

44 pid 1 (init), user 0 pid 3 (shell), user 1780 pid 2 (login), user 0 fork, exec

45 pid 1 (init), user 0 pid 3 (shell), user 1780 pid 2 (login), user 0 fork, exec fork, setuid, exec

46 user groups: /etc/group user may belong to multiple groups but has one “primary” group each file and directory is owned by one group each process has a real, effective, and saved group id binary files have setgid bit setegid and setgid

47 rwx rwx rwx usergroupother

48 rwx rwx rwx usergroupother if file_user_id == effective_user_id: user class else if file_group_id == effective_group_id: group class else: other

49 file permissions: read: can read bytes of file write: can modify bytes of file execute: can exec file

50 directory permissions: read: can get names of files write: can add/remove/rename files execute: can use in file paths

51 directory permissions: read: can get names of files write: can add/remove/rename files execute: can use in file paths /adams/taft/garfield/eisenhower

52 directory permissions: read: can get names of files write: can add/remove/rename files execute: can use in file paths /adams/taft/garfield/eisenhower /adams/taft/ (OK)

53 r-xr-xr-x rw-r----- r-x--x--x rwx /adams/lincoln /adams/cleveland /roosevelt /fillmore rwx rwx rwx usergroupother

54 dr-xrw-r-x /adams/ rwx rwx rwx usergroupother

55 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.


Download ppt "This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Unix system calls (part 1) history and."

Similar presentations


Ads by Google