1 / 10

CSC 552.201 - Advanced Unix Programming, Fall, 2008

CSC 552.201 - Advanced Unix Programming, Fall, 2008. Welcome back to UNIX System Programming! Monday, September 8, class 3. Before next class (Sept. 8). cp –pr ~parson/UnixSysProg ~/UnixSysProg chmod 700 ~/UnixSysProg ls –l ~/UnixSysProg

makani
Télécharger la présentation

CSC 552.201 - Advanced Unix Programming, Fall, 2008

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. CSC 552.201 - Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 8, class 3

  2. Before next class (Sept. 8) • cp –pr ~parson/UnixSysProg ~/UnixSysProg • chmod 700 ~/UnixSysProg • ls –l ~/UnixSysProg • For each of UnixSysProg/ forkexec redirectio multiplex • “cd” into directory, then “gmake clean test” • Examine and play with examples until you understand them. • Bring any questions to our next class.

  3. select() system call example • ~parson/UnixSysProg/lecture2/multiplex • usage: multiplex INFILE [ INFILE . . . ] INFILE0 INFILE1 … select() INFILE0 INFILEn read()/write() loop • select() can block on a SET of file IO handles (includes pipes and sockets) until some are ready for IO. There is no need to poll (yuck)!

  4. Directory system calls and libraries • int chdir(const char *path); • int fchdir(int fildes); • Comparable to shell’s “cd” in an executable process. • You can open() and directory, cannot read() or write() • Current process directory is global to all threads. • char *getcwd(char *buf, size_t size); • Comparable to shell’s “pwd” in an executable process. • BUT, the O.S. does not track symbolic link crossage!!! • Unlike shell’s “pwd,” getcwd() always returns hard path.

  5. Directory access • DIR *opendir(const char *dirname); • DIR *fdopendir(int fildes); • struct dirent *readdir(DIR *dirp); • Very loosely similar to “ls” command. • ino_t d_ino; /* serial number */ char d_name[]; • void rewinddir(DIR *dirp); • void seekdir(DIR *dirp, long int loc); • int closedir(DIR *dirp);

  6. File and directory status • int stat OR lstat(const char *restrict path, struct stat *restrict buf); • lstat returns data about a symbolic link, stat about the target file of a symbolic link • S_ISDIR, S_ISREG, S_ISFIFO, S_ISLNK, ... on buf.st_mode • S_I[RWX][USR][GRP][OTH], S_IRWX[UGO], S_IS[UG]ID • file size, number of links, and other attributes of the file • int access(const char *path, int amode); • R_OK | W_OK | X_OK | F_OK

  7. UNIX file system, Fig. 5.3 in text inode size (in bytes) owner UID and GID relevant times (creation, modification, access) link and block counts permissions direct pointers to beginning file blocks single indirect pointer block of direct pointers double indirect pointer triple indirect pointer

  8. Hard and soft links • int link(const char *existing, const char *new); • like “ln” command. • The non-directory files must be in same file system. • int unlink(const char *path); • like “rm” command • File not removed until after last hard link is gone. • int symlink(const char *name1, const char *name2); • Like “ln –s” command, a soft link may cross file systems.

  9. UNIX 3C library file IO • These are buffered library functions, with limited formatting and parsing, that are counterparts to many level 2 system calls. • Declared in stdio.h and stdlib.h, an open file is represented by a FILE * opaque type. • fopen(), popen(), fclose(), fgets(), fputs(), fprintf(), fscanf() • Standard IO files and stdin, stdout and stderr.

  10. Level 2 pipes and FIFOs • int pipe(int fildes[2]); • Like the shell command “|” operation. • Returns an open input on [0] and output on [1]. • This anonymous “file” is used for inter-process communication (IPC) across threads or fork/exec. • int mkfifo(const char *path, mode_t mode); • int mknod(const char *path, mode_t mode, dev_t dev); // mode includes S_IFIFO or S_IFREG • Shell “mkfifo” or “mknod … p”, can be used for barrier.

More Related