1 / 55

http:// codeschool.org /

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

ivrit
Download Presentation

http:// codeschool.org /

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. It’s a Unix system!

  5. 1980’s System V BSD

  6. today Linux Mac OS X FreeBSD, OpenBSD

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

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

  9. … system call 7 0xFF 31 01 11 system call 6 0xFF 90 44 44 system call 5 0xFF 31 01 11 system call 4 0xFF 31 21 14 system call 3 0xA2 22 00 10 system call 2 0x82 87 95 94 system call 1 0x20 15 10 00 system call 0 0x76 00 00 00

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

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

  12. created terminated waiting running blocked

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

  14. ssize_t read(intfd, void *buf, size_t count);

  15. ssize_t read(intfd, void *buf, size_t count); read(fd)

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

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

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

  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. kernel code stack heap mmap fails when not enough space heap heap heap uninitialized data initialized data code

  22. garbage collection

  23. iffork() == 0: …// new (child) process else: …// original (parent) process

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

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

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

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

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

  29. exec stack heap heap code

  30. exec code (executable)

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

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

  33. _exit (terminate the process) _exit(0)

  34. wait (block the process until child process terminates) pid = fork() ifpid == 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 17, user 4 • pid 85, user 8 • pid 34, user 4 • pid 230, user 8 • pid 24, user 33 pid 1 (init), user 0 • pid 104, user 33 • 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: “real” id: the owning user “effective” id: determines privileges “saved” id: set by exec to match the effective id each file and directory is owned by a single user

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

  41. 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)

  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. pid2 (login), user 0 pid 1 (init), user 0 • pid3 (shell), user 1780

  44. fork, exec • pid2 (login), user 0 pid 1 (init), user 0 • pid3 (shell), user 1780

  45. fork, exec • pid2 (login), user 0 pid 1 (init), user 0 fork, setuid, exec • pid3 (shell), user 1780

  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. rwxrwxrwx user group other

  48. rwxrwxrwx user group other if file_user_id == effective_user_id: user class else iffile_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

More Related