File System Abstraction - Advanced Unix Programming - Lecture Slides, Slides of Computer Programming

Some concept of Advanced Unix Programming are Address Structure, Basic Thread Functions, Client-Server Design, Network Programming, Signals and Thread, Thread-Specific Data, Unix File System, Reliable Communication. Main points of this lecture are: File System Abstraction, Unix File System, Directories, File Descriptors, Programming, Unlink, Variable Argument List, Process Management, Redirection, Named and Unnamed Pipes

Typology: Slides

2012/2013

Uploaded on 04/29/2013

parmita
parmita 🇮🇳

4.7

(17)

183 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Week 3 Topics
UNIX file system
File system abstraction
Directories
File descriptors
Unix API Programming Examples and Techniques
Example with direct IO
open, close, fdopen, lseek, unlink
Variable argument list
Docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download File System Abstraction - Advanced Unix Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Week 3 Topics

  • UNIX file system
    • File system abstraction
    • Directories
    • File descriptors
  • Unix API Programming Examples and Techniques
    • Example with direct IO
      • open, close, fdopen, lseek, unlink
    • Variable argument list

Week 3 Topics ... continued

  • File I/O
    • File descriptors
      • open, creat, close, dup, dup
    • I/O redirection
  • Process management
    • fork, exit, wait, waitpid, execv
  • Pipes
    • Named and unnamed pipes
    • Implementing pipe in a shell

File descriptors

  • Implication of the file descriptor/open file

descriptions/inode table organization in UNIX

  • open and creat
    • search for the first empty slot in the process file descriptor table
    • allocate an open file description in the file table, which has a pointer to the inode table
    • See example1.c
  • dup and dup
    • Duplicate the file descriptor in the process file descriptor table
    • See example1b.c
    • Where is the current file position stored?

I/O redirection

  • All UNIX processes have three predefined files

open

  • stdin -- STDIN_FILENO (0)
  • stdout -- STDOUT_FILENO (1)
  • stderr -- STDERR_FILENO (2)
  • We can redirect the I/O by manipulating these file

descriptors

  • See example2.c and example3.c

fork()

• fork()

  • Create a new process by duplicating the

context of the calling process

  • The calling process is called the parent , and the

new process the child

  • The return value of fork() distinguishes the two

processes

  • See example4.c and example5.c

exit() and wait()

  • exit (int status)
    • Clean up the process (for example, close all files)
    • Tell its parent that it is dying (SIGCHLD)
    • Tell child processes that it is dying (SIGHUP)
    • status can be accessed by the parent
  • wait, waitpid
    • Wait for a child process to die
      • pid_t wait(int *stat_loc)
    • Suspend the calling process to wait for a child process to die - Return the pid and status of the child process
  • See example6.c