Forum: D2L Discussion - Participation is expected Deadlock vs Starvation - Under starvation, some, but not all processes are unable to make progress. - Under deadlock, the system (all processes) can't make progress. ----------------------------------------- File|I/O Device Representation C++|Java: Streams (object) - Standard: cin, cout, cerr - Library: - Seek: seekg, seekp (g=get, p=put) - Open: , , C: File Pointer (address) - Standard: stdin, stdout, stderr - Library: , in C++ referred to as (by g++) - Seek: fseek() - stdio library call - Open: fopen - stdio library call Unix (System): File descriptor (int) - Standard: 0, 1, 2 - Library: None. These are system calls, i.e. they are built into the operating system. - Seek: lseek - Open: open Compilers: - g++ for C++; can handle Unix/C - gcc for Unix/C C and Unix are coupled. The system language of Unix IS C. Permissions on files are set from the shell using chmod. - The system call open() requires permissions to be specified on newly created files. - Others use a default value set in the shell Most system calls return 0=success, -1=failure Unix open() examples/exercises, with C/stdio & C++ equivalent - assume fstream file: 1. Open a file named abc.txt for writing, only if it exists. If it does, the present contents should be preserved, and writing should occur after the present contents. result=open("abc.txt",O_WRONLY|O_APPEND); C++: file.open("abc.txt",ios::read); if (file.is_open()) { file.close(); file.open("abc.txt",ios::write|ios::app); Notes: - For an fstream, ios::write does not automatically clobber (i.e. truncate). - For an ofstream, ios::write does truncate unless or'd with ios::ate or ios::app * ate means you can start writing at the end if you like * app means that the location pointer seeks to eof before any write takes place. stdio.h: FILE *fPtr; fPtr=fopen(("abc.txt","r"); if (fPtr) { fclose(fPtr); fPtr= fopen("abc.txt","a"); } Give an open() command equivalent to the C++ command Dest.open(“abc.txt”), where Dest is an ofstream