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 2)

Similar presentations


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

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

2 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.

3 open (open/create a file and return a file descriptor) close (release file descriptor) read (copy bytes from a file to memory)* write (copy bytes of memory to a file)* *blocks

4 Process OS syscall write write buffer HD

5 f = open(‘/alice/tim’) write(f, ‘bla bla’) write(f, ‘bla bla bla’) close(f)

6 Process OS data and code syscall read read buffer HD

7 f = open(‘/alice/tim’) data = read(f) close(f)

8 f = open(‘/alice/tim’) data = read(f) while len(data) != 0: print(data) data = read(f) close(f)

9 byte 0last byte marker

10 byte 0last byte marker

11 byte 0last byte move with truncate

12 byte 0last byte move with truncate move with lseek marker

13 descriptor description

14 f = open(‘/alice/tim’) f2 = open(‘/alice/tim’) write(f, ‘bla bla’) data = read(f2)

15 descriptor description buffer file on disk

16 pid 75 write byte 0last byte pid 580 write pid 442 read pid 46 write

17 pid 75 write byte 0last byte pid 580 write ‘bla bla’ ‘herp derp’

18 pid 75 write byte 0last byte pid 580 write ‘her blap’ ‘blrp derp’ ‘hlapbder p’ ‘herp derp’ ‘bla bla’

19 umask (get/set default permissions for new files/directories) oldmask = umask(newmask) f = open(‘/alice/tim’) write(f, ‘bla bla’)

20 chmod (‘change mode’: set permissions of an existing file/directory) chmod(‘/alice/tim’, mask)

21 chmod (‘change mode’: set permissions of an existing file/directory) chown (‘change owner’: set owner of an existing file/directory) chmod(‘/alice/tim’, mask) chown(‘/alice/tim’, user, group)

22 HD partition 1 partition 2 partition 3 HD partition 4 flash drive partition 5 CD-ROM partition 6 partition 7

23 file 35 file 7 file 61 file 4 directory 21 directory 86 root directory 2  root directory always has inode 2 each file and directory in a partition is known by a unique inode number

24 mkdir (‘make directory’) rmdir (‘remove a file or directory’) mkdir(‘/alice/tim’) rmdir(‘/alice/tim’)

25 link (add directory entry) link(‘/alice/ian’, ‘/ben/jill’)

26 link (add directory entry) unlink (remove directory entry) link(‘/alice/ian’, ‘/ben/jill’) unlink(‘/alice/ian’)

27 getdents (‘get directory entries’) f = open(‘/alice’) entries = getdents(f) while len(entries) != 0: print(entries) entries = getdents(f) close(f)

28 HD partition 1 partition 2 partition 3 flash drive partition 4 / /alice/tim /jessica/vincent /jessica

29 mount (attach partition to the unified file system) umount (‘unmount’: detach partition from the unified file system) mount(partition1, ‘/alice/tim’) umount(‘/alice/tim’)

30 absolute path: /alice/tim relative path: alice/tim

31 chdir (change cwd, the ‘current working directory’) chdir(‘/ben/ian’) f = open(‘/alice/tim’) f2 = open(‘alice/tim’) becomes: ‘/ben/ian/alice/tim’

32 ‘regular’ file directory symbolic link character device file block device file pipe socket

33 symlink (create a symbolic link) symlink(‘/alice/tim’, ‘/jill/ken’) f = open(‘/jill/ken’) follows link to: ‘/alice/tim’

34 CPU registers device read/write 

35  a block may only be read/written as a whole partition composed of blocks block 0 block 1 block 2 block 3 block 4 block 5 block 6 block 7 block 8 block 9

36 partition composed of blocks block 0 block 1 inode 86 block 2 block 3 block 4 inode 86 block 5 block 6 inode 86 block 7 block 8 block 9

37 read/write block 0 block 1 inode 86 block 2 block 3 block 4 inode 86 block 5 block 6 inode 86 block 7 block 8 block 9 block 4 buffer

38 block 0 block 1 block 2 block 3 block 4 block 5 block 6 block device file byte 0 last byte

39 device output buffer input buffer process character device file read write input output

40 data taken starting here data appended here input/output buffers are FIFO (first in, first out)

41 read takes data starting here device appends data here input buffer

42 input/output buffers are FIFO (first in, first out) device takes data starting here write appends data here output buffer

43 block device buffers backed by storage character device buffers not backed by storage

44 /dev bf = open(‘/dev/sda1’) cf = open(‘/dev/lp0’) directory of device files

45 /dev bf = open(‘/dev/sda1’) cf = open(‘/dev/lp0’) lseek(bf, 100) bdata = read(bf) cdata = read(cf) directory of device files

46 pseudo-device files /dev/zero returns zeroed bytes /dev/random returns random data /dev/null discards data; returns no bytes at all

47 pipe (a FIFO as a file) read takes data starting here write appends data here

48 FIFO process A pipe readwrite process B

49 FIFO process A pipe readwrite process B FIFO readwrite pipe

50 mknod (‘make node’: create a regular file, device file, or named pipe) mknod(‘/ryan/kim’, BLOCK, deviceNum) mknod(‘/ryan/erin’, CHR, deviceNum) mknod(‘/ryan/tina’, FIFO)

51 pipe (creates a new, anonymous pipe and returns two file descriptors) fs = pipe() f1 = fs[0] f2 = fs[1]

52 memory-mapped files file stack code mmap’d file heap kernel code byte 0 byte n

53 f = open(‘/brad/mike’) address = mmap(500, f, 200) … # reading/writing the allocated memory reads/writes the file munmap(address) close(f) memory-mapped files

54 signals signals are sent by… the kernel the receiving process… performs a default action or invokes a handler function or blocks it or ignores it

55 signals signals are sent by… the kernel SIGSEGV SIGFPE SIGSTOP SIGCONT the receiving process… performs a default action or invokes a handler function or blocks it or ignores it

56 signals signals are sent by… the kernel or the kill system call SIGSEGV SIGFPE SIGSTOP SIGCONT the receiving process… performs a default action or invokes a handler function or blocks it or ignores it

57 kill (send a signal to a process) signal (set a signal to be handled, ignored, or trigger its default action) kill(35, SIGSTOP) signal(func, SIGFPE)

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

59 lockf (obtains/releases an “advisory” lock on a file) f = open(‘/alice/tim’) lockf(f, F_LOCK) … # do stuff to file lockf(f, F_ULOCK) close(f)

60 stat (get file/directory information: size, last modification date/time, owner, etc.) status = stat(‘/alice/tim’)

61 HD partition 1 partition 2 partition 3 flash drive partition 4 / /alice/tim /jessica/vincent /jessica

62 chroot (change root directory) chroot(‘/ben/ian’) open(‘/alice/tim’) absolute path: ‘/ben/ian/alice/tim’


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

Similar presentations


Ads by Google