Homework 4 Answers. Due Date: Monday, May 27, 2002, at 11:59PM Points: 100. /* * macros */ #define SZBUFFER 1024 /* max length of input buffer */

Size: px
Start display at page:

Download "Homework 4 Answers. Due Date: Monday, May 27, 2002, at 11:59PM Points: 100. /* * macros */ #define SZBUFFER 1024 /* max length of input buffer */"

Transcription

1 Homework 4 Answers Due Date: Monday, May 27, 2002, at 11:59PM Points: 100 UNIX System 1. (10 points) How do I delete the file i? Answer: Either rm./-i or rm -- -i will work. 2. (15 points) Please list all sections of the manual on the CSIF Linux systems containing a command named time. What are the file names of those manual pages? Answer: The command man -a time will print the appropriate man pages, which are time(1), time(2), and time(n). The command man -a -w time gives the names of the file containing each manual page. The file names are /usr/share/man/man1/time.1.gz, /usr/share/man/man2/time.2.gz, and /usr/share/man/mann/time.n.gz, respectively. C Programming 3. (30 points) A palindrome is a word or sentence which is the same whether read backwards or forwards. Please write a program ispal.c which reads each line from its standard input and says whether or not the line is a palindrome. For each line, all non-alphanumeric characters are to be ignored, and case is not to matter. For example, Hint: use recursion. standard input Madam, I'm Adam! O give me a home Able was I ere I saw Elba Answer: Here is my program. It uses recursion. standard output A palindrome Not a palindrome A palindrome * ispal.c Matt Bishop * * This program tests a line of input to see if it * is a palindrome #include <stdio.h> * macros #define SZBUFFER 1024 max length of input buffer * forward declarations void shrink(char *); eliminate non-alphanumerics int ispal(char *, char *); test for palindromosity * this reads each line, calls a function (shrink) * to clobber non-alphanumerics, and then prints a message * about whether the input is a palindrome void main(void) Version of June 2, :51 pm Page 1 of 11

2 char buf[szbuffer]; input buffer register int len; length of input line * loop until user is done while(fgets(buf, SZBUFFER, stdin)!= NULL) clobber all non-alphanumerics (including the newline) shrink(buf); check for error if ((len = strlen(buf)) == 0) printf("no string given\n"); else no error -- check for palindromeness (?!) printf("%s palindrome\n", ispal(buf, &buf[len-1])? "A" : "Not a"); * exit nicely exit(0); * shrink: eliminate all non-alphanumerics, in place * arguments: char *buf string to be shrunk * return: nothing; string reduced in place * output: none void shrink(char *buf) register char *p; next char to look at register char *n; where to put it * go through the array, moving all alphanumerics to the * front of the array and clobbering everything else for(n = p = buf; *p; p++) if not alphanumeric, skip it if (!isalnum(*p)) continue; alphanumeric; make lower case (for consistency) *n++ = isupper(*p)? tolower(*p) : *p; add string terminator *n = '\0'; * ispal: is it a palindrome? Version of June 2, :51 pm Page 2 of 11

3 * arguments: char *buf beginning of string * char *ebuf end of string * return: 1 if the string (buf,..., ebuf) is a palindrome * 0 if the string (buf,..., ebuf) is not a palindrome * output: none int ispal(char *buf, char *ebuf) * first, the special cases be sure there is a string to check! if (buf >= ebuf) if first and last differ, it isn't if (*buf!= *ebuf) * and now recurse if the same, check the inner part of the string return(ispal(buf+1, ebuf-1)); 4. (30 points) Write a program to list the files in a directory in the order in which the directory entries occur. Your program is to use the library functions opendir (3), readdir(3), and closedir(3). Your output should include the number of the directory entry, the inode number of the file, and the file name. For example, in a directory containing the files a.out and d.c, the output might look like: order inode name d.c a.out Hint: On the Linux systems in the CSIF, the inode field of the dirent structure is d_ino. Please see the manual pages for the functions for more details. (The inode field is not documented there, but the field containing the name of the file is.) Answer: * dumpdir -- Matt Bishop * This program dumps the file names in a directory file in the order * in which they occur; it also prints the inode numbers #include <stdio.h> #include <sys/types.h> #include <dirent.h> * dumpdir: open directory file, dump contents * arguments: char *dname name of directory * return: 0 on success * 1 on error/failure * output: inode/name pairs in order of directory contents Version of June 2, :51 pm Page 3 of 11

4 int dumpdir(char *dname) DIR *dp; points to directory struct dirent *dent; pointer to directory entry int counter; position in listing * open the directory if ((dp = opendir(dname)) == NULL) perror(dname); * print header printf("%s:\n%5s\t%10s\t%s\n", dname, "count", " inode ", "name"); * just go through directory one entry at a time for(counter = 1; (dent = readdir(dp))!= NULL; counter++) printf("%5d\t%10d\t%s\n", counter, dent->d_ino, dent->d_name); * close it -- ignore errors here (void) closedir(dp); * the main routine int main(int argc, char *argv[]) process arguments if (argc == 1) return(dumpdir(".")); else if (argc == 2) return(dumpdir(argv[1])); more than 1 argument -- error fprintf(stderr, "Usage: %s [ directory ]\n", argv[0]); Version of June 2, :51 pm Page 4 of 11

5 Debugging 5. (15 points) On the web page for the class is the source for a set of routines to manage a linked list. The functions provided are: int insert(struct link **head, int value) Insert value into the linked list pointed to by *head; update *head if necessary. If the insertion succeeds, return 1; if it fails, return 0. int delete(struct link **head, int value) Delete value from the linked list pointed to by *head; update *head if necessary (if the list is empty, make it NULL). If the deletion succeeds, return 1; if it fails (because value is not in the list), return 0. void prforw(struct link *head) Print all integers in the linked list pointed to by head in order (from head to tail). void prback(struct link *head) Print all integers in the linked list pointed to by head in reverse order (from tail to head). Unfortunately, they don't quite work right. Debug them. Turn in commented, corrected routines; be sure you mark what changes were made, and why! Hints: The program testll.c is a program that calls the library routines to manage a linked list of numbers. You can use it to help figure out what the problems are. The manual page on the web tells you how to use that program. Both the file containing the routines, llist.c, and the test program, testll.c, require the header file llist.h. Answer: * llist.c Matt Bishop * * This is a library of linked list functions: * insert -- inserts a value into the linked list * delete -- deletes a value from the linked list * prforw -- prints the values in the list in order * prback -- prints the values in the list in reverse order #include "llist.h" * insert: insert a value into a linked list * arguments: LLIST **head address of pointer to head * of linked list * int value value to be inserted * return: 1 insertion succeeded; on return, head points * to the address of the (possibly new) head of * the linked list * 0 insertion failed * output: none * exceptions: memory cannot be allocated (returns 0) int insert(llist **head, int value) register LLIST *p, *q; pointers to walk linked list * you can argue whether or not this next line had a bug, * but it certainly was poor style, since lalloc is * called below! Version of June 2, :51 pm Page 5 of 11

6 register LLIST *temp; points to new node * CONSTRUCT NEW NODE FOR THE LINKED LIST if ((temp = lalloc()) == NULL) temp->val = value; temp->next = L_NULL; * if an empty list, make this node the head if (*head == NULL) *head = temp; ********** BUG FIX #1 ******************************* * add code to deal with inserting before head of list if ((*head)->val > value) temp->next = *head; *head = temp; ********** END BUG FIX #1 *************************** * walk the linked list; after this loop, * you'll need to insert the new node between * p and q for(p = *head; p!= NULL && p->val < value; p = p->next) q = p; * insert the new node and return success q->next = temp; temp->next = p; * delete: delete a value from a linked list * arguments: LLIST **head address of pointer to head * of linked list * int value value to be deleted * return: 1 deletion succeeded; on return, head points * to the address of the (possibly new) head of * the linked list * 0 deletion failed Version of June 2, :51 pm Page 6 of 11

7 * output: none * exceptions: pointer to pointer to head of list is NULL (return 0) * no node in the list contains value (return 0) int delete(llist **head, int value) register LLIST *p, *q; used to locate node in list * if an empty list, nothing to delete if (*head == NULL) * value is at the head of linked list if ((*head)->val == value) make head point to next one p = *head; *head = (*head)->next; free it and return success (void) free(p); * figure out where the node to be deleted is * after this loop, if there is a node with the given * value in the linked list, p points to it, and * q points to its predecessor for(p = *head; p!= NULL && p->val < value; p = p->next) q = p; see if the value is in the list if (p->val!= value) ********** BUG FIX #2 ******************************* * make next of element before deleted element * point to element after deleted element q->next = p->next; ********** END BUG FIX #2 *************************** * release the deleted node and return success (void) free(p); * prforw print list * arguments: LLIST *head pointer to head of linked list Version of June 2, :51 pm Page 7 of 11

8 * return: nothing * output: list of values in linked list, one per line * exceptions:none void prforw(llist *head) register LLIST *p; pointer in a for loop * walk the list, printing as you go for(p = head; p!= NULL; p = p->next) printf("%d\n", p->val); * prback print list backwards * arguments: LLIST *head pointer to head of linked list * return: nothing * output: list of values in linked list (reversed), one per line void prback(llist *head) if list is empty, print nothing if (head == NULL) return; print rest of list (void) prback(head->next); print this node printf("%d\n", head->val); Extra Credit 6. (10 points) Modify the program you wrote in problem 4 to use the scandir(3) function to sort the files by either inode number (option i) or name (option n). Answer: * dumpdir -- Matt Bishop * This program dumps the file names in a directory file in the order * in which they occur; it also prints the inode numbers #include <stdio.h> #include <sys/types.h> #include <dirent.h> * global telling us how to sort int (*dsort)(const struct dirent **, const struct dirent **) = NULL; Version of June 2, :51 pm Page 8 of 11

9 * sort on inode * returns > 0 if first arg has larger inode than second * returns = 0 if first arg has same inode than second * returns < 0 if first arg has smaller inode than second int cmpino(const struct dirent **a, const struct dirent **b) return((*a)->d_ino - (*b)->d_ino); * sdumpdir: open directory file, dump contents in sorted order * arguments: char *dname name of directory * return: 0 on success * 1 on error/failure * output: inode/name pairs in order of directory contents int sdumpdir(char *dname) struct dirent **namelist; sorted directory entries int counter; position in listing int nent; number of directory entries if ((nent = scandir(dname, &namelist, NULL, dsort)) < 0) fprintf(stderr, "sort of directory entries failed\n"); * print header printf("%s (%d):\n%5s\t%10s\t%s\n", dname, nent, "count", " inode ", "name"); * just go through directory one entry at a time for(counter = 0; counter < nent; counter++) printf("%5d\t%10d\t%s\n", counter, namelist[counter]->d_ino, namelist[counter]->d_name); * udumpdir: open directory file, dump contents in directory order * arguments: char *dname name of directory * return: 0 on success * 1 on error/failure * output: inode/name pairs in order of directory contents int udumpdir(char *dname) Version of June 2, :51 pm Page 9 of 11

10 DIR *dp; points to directory struct dirent *dent; pointer to directory entry int counter; position in listing * open the directory if ((dp = opendir(dname)) == NULL) perror(dname); * print header printf("%s:\n%5s\t%10s\t%s\n", dname, "count", " inode ", "name"); * just go through directory one entry at a time for(counter = 1; (dent = readdir(dp))!= NULL; counter++) printf("%5d\t%10d\t%s\n", counter, dent->d_ino, dent->d_name); * close it -- ignore errors here (void) closedir(dp); * dumpdir: call right directory dumper, sorted or unsorted * arguments: char *dname name of directory * return: value of right directory dumper * output: none per se; only from called routine int dumpdir(char *dname) if not to be sorted, called unsort dumper if (dsort == NULL) return(udumpdir(dname)); call sorted directory dumper return(sdumpdir(dname)); * the main routine int main(int argc, char *argv[]) Version of June 2, :51 pm Page 10 of 11

11 int i = 1; counter in a for loop * first do options if (argc > 1) for(i = 1; i < argc && argv[i][0] == '-'; i++) if (strcmp(argv[i], "-i") == 0) dsort = cmpino; else if (strcmp(argv[i], "-n") == 0) dsort = alphasort; else fprintf(stderr, "%s: invalid option\n", argv[i]); fprintf(stderr, "Usage: %s [ -i -n ] [ directory ]\n", argv[0]); * now process directories if (i == argc) return(dumpdir(".")); else if (i == argc - 1) return(dumpdir(argv[i])); more than 1 argument -- error fprintf(stderr, "Usage: %s [ -i -n ] [ directory ]\n", argv[0]); Version of June 2, :51 pm Page 11 of 11

Homework 2 Answers. Due Date: Monday, April 29, 2002, at 11:59PM Points: 100

Homework 2 Answers. Due Date: Monday, April 29, 2002, at 11:59PM Points: 100 Homework 2 Answers Due Date: Monday, April 29, 2002, at 11:59PM Points: 100 UNIX System 1. (10 points) What program is running as process #1? Type ps ax and look for the process with a PID of 1. Then look

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight Exercise 7 due Monday (out later today) POSIX Portable Operating System Interface Family of standards specified by the

More information

Last Week: ! Efficiency read/write. ! The File. ! File pointer. ! File control/access. This Week: ! How to program with directories

Last Week: ! Efficiency read/write. ! The File. ! File pointer. ! File control/access. This Week: ! How to program with directories Overview Unix System Programming Directories and File System Last Week:! Efficiency read/write! The File! File pointer! File control/access This Week:! How to program with directories! Brief introduction

More information

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 Homework 5 Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 UNIX System 1. (10 points) I want to make the file libprog.a in my home directory available to everyone so

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight HW2 Due Thursday, July 19 th Midterm on Monday, July 23 th 10:50-11:50 in TBD (And regular exercises in between) POSIX

More information

structs as arguments

structs as arguments Structs A collection of related data items struct record { char name[maxname]; int count; ; /* The semicolon is important! It terminates the declaration. */ struct record rec1; /*allocates space for the

More information

OPERATING SYSTEMS: Lesson 12: Directories

OPERATING SYSTEMS: Lesson 12: Directories OPERATING SYSTEMS: Lesson 12: Directories Jesús Carretero Pérez David Expósito Singh José Daniel García Sánchez Francisco Javier García Blas Florin Isaila 1 Goals To know the concepts of file and directory

More information

Overview. Unix System Programming. Outline. Directory Implementation. Directory Implementation. Directory Structure. Directories & Continuation

Overview. Unix System Programming. Outline. Directory Implementation. Directory Implementation. Directory Structure. Directories & Continuation Overview Unix System Programming Directories & Continuation Maria Hybinette, UGA 1 Last Week: Efficiency read/write The File File pointer File control/access Permissions, Meta Data, Ownership, umask, holes

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 3 Oral test Handin your slides Time Project 4 Due: 6 Dec Code Experiment report Operating System Labs Overview of file system File

More information

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am) Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Reid Section: L0101 (10:10-11:00am) Do not turn this page until you have received the signal to start.

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 15: Unix interface: low-level interface Cristina Nita-Rotaru Lecture 15/Fall 2013 1 Streams Recap Higher-level interface, layered on top of the primitive file descriptor

More information

CSC 271 Software I: Utilities and Internals

CSC 271 Software I: Utilities and Internals CSC 271 Software I: Utilities and Internals Lecture 13 : An Introduction to File I/O in Linux File Descriptors All system calls for I/O operations refer to open files using a file descriptor (a nonnegative

More information

CSCI 2132 Final Exam Solutions

CSCI 2132 Final Exam Solutions Faculty of Computer Science 1 CSCI 2132 Final Exam Solutions Term: Fall 2018 (Sep4-Dec4) 1. (12 points) True-false questions. 2 points each. No justification necessary, but it may be helpful if the question

More information

System Programming. Introduction to Unix

System Programming. Introduction to Unix Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Introduction

More information

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology Lecture 7: Data Structures 1 Introduction: dynamic array Conventional array in C has fix number of elements Dynamic array is array with variable number of elements: actually a pointer and a variable indicating

More information

CS 0449 Sample Midterm

CS 0449 Sample Midterm Name: CS 0449 Sample Midterm Multiple Choice 1.) Given char *a = Hello ; char *b = World;, which of the following would result in an error? A) strlen(a) B) strcpy(a, b) C) strcmp(a, b) D) strstr(a, b)

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 4 (multi-thread & lock): Due: 10 Dec Code & experiment report 18 Dec. Oral test of project 4, 9:30am Lectures: Q&A Project 5: Due:

More information

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga Arrays and Strings Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana February 23, 2015 Outline General memory model Definition and use of pointers Invalid pointers and common

More information

Tutorial 1 C Tutorial: Pointers, Strings, Exec

Tutorial 1 C Tutorial: Pointers, Strings, Exec TCSS 422: Operating Systems Institute of Technology Spring 2017 University of Washington Tacoma http://faculty.washington.edu/wlloyd/courses/tcss422 Tutorial 1 C Tutorial: Pointers, Strings, Exec The purpose

More information

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty. ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.

More information

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID: Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering Mid-term Exam Name: This exam is closed book and notes. Read the questions carefully and focus your answers on what has

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

just a ((somewhat) safer) dialect.

just a ((somewhat) safer) dialect. Intro_to_C Page 1 Intro to C Tuesday, September 07, 2004 5:30 PM C was developed specifically for writing operating systems Low level of abstraction. "Just above machine language." Direct access to the

More information

The UNIX File System. File Systems and Directories UNIX inodes Accessing directories Understanding links in directories.

The UNIX File System. File Systems and Directories UNIX inodes Accessing directories Understanding links in directories. The UNIX File System File Systems and Directories UNIX s Accessing directories Understanding links in directories Reading: R&R, Ch 5 Directories Large amounts of data: Partition and structure for easier

More information

#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;

#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0; 1. Short answer questions: (a) Compare the typical contents of a module s header file to the contents of a module s implementation file. Which of these files defines the interface between a module and

More information

CSE 303 Midterm Exam

CSE 303 Midterm Exam CSE 303 Midterm Exam October 29, 2008 Name Sample Solution The exam is closed book, except that you may have a single page of hand written notes for reference. If you don t remember the details of how

More information

CSE 333 Autumn 2014 Midterm Key

CSE 333 Autumn 2014 Midterm Key CSE 333 Autumn 2014 Midterm Key 1. [3 points] Imagine we have the following function declaration: void sub(uint64_t A, uint64_t B[], struct c_st C); An experienced C programmer writes a correct invocation:

More information

csci-e28 lecture 4samples page 1

csci-e28 lecture 4samples page 1 csci-e28 lecture 4samples page 1 :::::::::::::: perror_demo.c :::::::::::::: #include #include program perror_demo.c * purpose show how errno is set by syscalls * and how perror prints

More information

Exercise Session 2 Systems Programming and Computer Architecture

Exercise Session 2 Systems Programming and Computer Architecture Systems Group Department of Computer Science ETH Zürich Exercise Session 2 Systems Programming and Computer Architecture Herbstsemester 216 Agenda Linux vs. Windows Working with SVN Exercise 1: bitcount()

More information

Introduction. Files. 3. UNIX provides a simple and consistent interface to operating system services and to devices. Directories

Introduction. Files. 3. UNIX provides a simple and consistent interface to operating system services and to devices. Directories Working With Files Introduction Files 1. In UNIX system or UNIX-like system, all input and output are done by reading or writing files, because all peripheral devices, even keyboard and screen are files

More information

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

More information

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID: Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering Mid-term Exam Name: This exam is closed book and notes. Read the questions carefully and focus your answers on what has

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE264 Fall 2013 Exam 3, November 20, 2013 ECE264 Fall 2013 Exam 3, November 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

CS , Spring Sample Exam 3

CS , Spring Sample Exam 3 Andrew login ID: Full Name: CS 15-123, Spring 2010 Sample Exam 3 Mon. April 6, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the

More information

CSCI-E28 Lecture 4 Outline. Internal Structure of Files, Directories, File Systems. Work from user view tosystem view, write pwd

CSCI-E28 Lecture 4 Outline. Internal Structure of Files, Directories, File Systems. Work from user view tosystem view, write pwd CSCI-E28 Lecture 4 Outline Topics: Approach: Internal Structure of Files, Directories, File Systems Work from user view tosystem view, write pwd Featured Commands: mkdir, rmdir, rm, ln, mv, pwd Main Ideas:

More information

ECE 2035 Programming HW/SW Systems Spring problems, 7 pages Exam One Solutions 4 February 2013

ECE 2035 Programming HW/SW Systems Spring problems, 7 pages Exam One Solutions 4 February 2013 Problem 1 (3 parts, 30 points) Code Fragments Part A (5 points) Write a MIPS code fragment that branches to label Target when register $1 is less than or equal to register $2. You may use only two instructions.

More information

APT Session 4: C. Software Development Team Laurence Tratt. 1 / 14

APT Session 4: C. Software Development Team Laurence Tratt. 1 / 14 APT Session 4: C Laurence Tratt Software Development Team 2017-11-10 1 / 14 http://soft-dev.org/ What to expect from this session 1 C. 2 / 14 http://soft-dev.org/ Prerequisites 1 Install either GCC or

More information

Exploring the file system. Johan Montelius HT2016

Exploring the file system. Johan Montelius HT2016 1 Introduction Exploring the file system Johan Montelius HT2016 This is a quite easy exercise but you will learn a lot about how files are represented. We will not look to the actual content of the files

More information

Chapter 1. Introduction

Chapter 1. Introduction Chapter 1. Introduction System Programming http://www.cs.ccu.edu.tw/~pahsiung/courses/sp 熊博安國立中正大學資訊工程學系 pahsiung@cs.ccu.edu.tw Class: EA-104 (05)2720411 ext. 33119 Office: EA-512 Textbook: Advanced Programming

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14 BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.

More information

SOFTWARE ARCHITECTURE 3. SHELL

SOFTWARE ARCHITECTURE 3. SHELL 1 SOFTWARE ARCHITECTURE 3. SHELL Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/login.php 2 Software Layer Application Shell Library MIddleware Shell Operating System Hardware

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

The UNIX File System

The UNIX File System The UNIX File System Magnus Johansson (May 2007) 1 UNIX file system A file system is created with mkfs. It defines a number of parameters for the system as depicted in figure 1. These paremeters include

More information

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID: Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering Final Exam Name: This exam is open book and notes. Read the questions carefully and focus your answers on what has been

More information

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls 1 Unix File I/O 2 Unix System Calls System calls are low level functions the operating system makes available to applications

More information

File IO and command line input CSE 2451

File IO and command line input CSE 2451 File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to

More information

The Dynamic Debugger gdb

The Dynamic Debugger gdb Introduction The Dynamic Debugger gdb This handout introduces the basics of using gdb, a very powerful dynamic debugging tool. No-one always writes programs that execute perfectly every time, and while

More information

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 4 C Pointers and Arrays 1/25/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L04 C Pointers (1) Common C Error There is a difference

More information

Lecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment.

Lecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment. Lecture 12 CSE 110 20 July 1992 Today we ll cover the things that you still don t know that you need to know in order to do the assignment. 1 The NULL Pointer For each pointer type, there is one special

More information

ECE264 Spring 2013 Final Exam, April 30, 2013

ECE264 Spring 2013 Final Exam, April 30, 2013 ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing

More information

CS 241 Data Organization Pointers and Arrays

CS 241 Data Organization Pointers and Arrays CS 241 Data Organization Pointers and Arrays Brooke Chenoweth University of New Mexico Fall 2017 Read Kernighan & Richie 6 Structures Pointers A pointer is a variable that contains the address of another

More information

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst Clicker Question #1 For a sequential workload, the limiting factor for a disk system is likely: (A) The speed of

More information

The UNIX File System

The UNIX File System The UNIX File System Magnus Johansson May 9, 2007 1 UNIX file system A file system is created with mkfs. It defines a number of parameters for the system, such as: bootblock - contains a primary boot program

More information

CS 33. Shells and Files. CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Shells and Files. CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Shells and Files CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Shells Command and scripting languages for Unix First shell: Thompson shell sh, developed

More information

Final CSE 131B Spring 2004

Final CSE 131B Spring 2004 Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)

More information

CSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science

CSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science CSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science Date: October 26, 1999 Time: 1:10 pm Duration: 50 minutes Notes: 1. This is a closed book test, no aids are allowed.

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

CSCE 313 Introduction to Computer Systems

CSCE 313 Introduction to Computer Systems CSCE 313 Introduction to Computer Systems Instructor: Dr. Guofei Gu http://courses.cse.tamu.edu/guofei/csce313 The UNIX File System File Systems and Directories Accessing directories UNIX s Understanding

More information

Matt Ramsay CS 375 EXAM 2 Part 1

Matt Ramsay CS 375 EXAM 2 Part 1 Matt Ramsay CS 375 EXAM 2 Part 1 Output: csserver:/home/mr56/cs375/exam2 > parent 1 75000 Multiples of 3 between 3 and 15000 add to 37507500 This total written to /home/mr56/tmp/file8771.out Multiples

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Bernhard Boser & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic

More information

Project 2: Shell with History1

Project 2: Shell with History1 Project 2: Shell with History1 See course webpage for due date. Submit deliverables to CourSys: https://courses.cs.sfu.ca/ Late penalty is 10% per calendar day (each 0 to 24 hour period past due). Maximum

More information

CS61, Fall 2012 Section 2 Notes

CS61, Fall 2012 Section 2 Notes CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors

More information

Common Misunderstandings from Exam 1 Material

Common Misunderstandings from Exam 1 Material Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself

More information

This is an open book, open notes exam. But no online or in-class chatting.

This is an open book, open notes exam. But no online or in-class chatting. Principles of Operating Systems Fall 2017 Final 12/13/2017 Time Limit: 8:00am - 10:00am Name (Print): Don t forget to write your name on this exam. This is an open book, open notes exam. But no online

More information

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables) Memory Allocation Memory What is memory? Storage for variables, data, code etc. How is memory organized? Text (Code) Data (Constants) BSS (Global and static variables) Text Data BSS Heap Stack (Local variables)

More information

8. Characters, Strings and Files

8. Characters, Strings and Files REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each). A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary

More information

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis EL2310 Scientific Programming LAB2: C lab session Patric Jensfelt, Andrzej Pronobis Chapter 1 Introduction 1.1 Reporting errors As any document, this document is likely to include errors and typos. Please

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

Here's how you declare a function that returns a pointer to a character:

Here's how you declare a function that returns a pointer to a character: 23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

Fall 2015 COMP Operating Systems. Lab #3

Fall 2015 COMP Operating Systems. Lab #3 Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute

More information

Armide Documentation. Release Kyle Mayes

Armide Documentation. Release Kyle Mayes Armide Documentation Release 0.3.1 Kyle Mayes December 19, 2014 Contents 1 Introduction 1 1.1 Features.................................................. 1 1.2 License..................................................

More information

File and Directories. Advanced Programming in the UNIX Environment

File and Directories. Advanced Programming in the UNIX Environment File and Directories Advanced Programming in the UNIX Environment stat Function #include int stat(const char *restrict pathname, struct stat *restrict buf ); int fstat(int fd, struct stat

More information

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

CSC209H Lecture 3. Dan Zingaro. January 21, 2015 CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without

More information

Arrays and Memory Management

Arrays and Memory Management Arrays and Memory Management 1 Pointing to Different Size Objects Modern machines are byte-addressable Hardware s memory composed of 8-bit storage cells, each has a unique address A C pointer is just abstracted

More information

CSE 333 Midterm Exam Sample Solution 5/10/13

CSE 333 Midterm Exam Sample Solution 5/10/13 Question 1. (18 points) Consider these two C files: a.c void f(int p); int main() { f(17); return 0; b.c void f(char *p) { *p = 'x'; (a) Why is the program made from a.c and b.c incorrect? What would you

More information

o Code, executable, and process o Main memory vs. virtual memory

o Code, executable, and process o Main memory vs. virtual memory Goals for Today s Lecture Memory Allocation Prof. David August COS 217 Behind the scenes of running a program o Code, executable, and process o Main memory vs. virtual memory Memory layout for UNIX processes,

More information

CS 220: Introduction to Parallel Computing. Input/Output. Lecture 7

CS 220: Introduction to Parallel Computing. Input/Output. Lecture 7 CS 220: Introduction to Parallel Computing Input/Output Lecture 7 Input/Output Most useful programs will provide some type of input or output Thus far, we ve prompted the user to enter their input directly

More information

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture CS 61C: Great Ideas in Computer Architecture Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c And in Conclusion, 2 Processor Control Datapath Components of a Computer PC Registers Arithmetic

More information

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 16, 2013 2:00 p.m. 4:30 p.m. (150 minutes) Examiners: J. Anderson, B. Korst, J.

More information

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009 Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009 April 16, 2009 Instructions: Please write your answers on the printed exam. Do not turn in any extra pages. No interactive electronic devices

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic

More information

CSE 333 Midterm Exam July 24, 2017 Sample Solution

CSE 333 Midterm Exam July 24, 2017 Sample Solution Sample Solution Question 1. (14 points) Making things. Suppose we have the following C header and implementation files, showing the various #include and #if directives in each one: widget.h #ifndef _WIDGET_H_

More information

ECE551 Midterm Version 1

ECE551 Midterm Version 1 Name: ECE551 Midterm Version 1 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual

More information

Midterm Exam 2 Solutions, C programming

Midterm Exam 2 Solutions, C programming Midterm Exam 2 Solutions, C programming April 26, 2010 Rules: Open book, open notes, open any printed or handwritten material. No electronic devices (except a music player). If you use a music player nobody

More information

ch = argv[i][++j]; /* why does ++j but j++ does not? */

ch = argv[i][++j]; /* why does ++j but j++ does not? */ CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Functions Similar to (static) methods in Java without the class: int f(int a, int

More information

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm)

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm) Final Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Reid Section: L5101 (6:10-7:00pm) Do not turn this page until you have received the signal to start.

More information

Part II Processes and Threads Process Basics

Part II Processes and Threads Process Basics Part II Processes and Threads Process Basics Fall 2017 Program testing can be used to show the presence of bugs, but never to show their absence 1 Edsger W. Dijkstra From Compilation to Execution A compiler

More information

Problem Set 1: Unix Commands 1

Problem Set 1: Unix Commands 1 Problem Set 1: Unix Commands 1 WARNING: IF YOU DO NOT FIND THIS PROBLEM SET TRIVIAL, I WOULD NOT RECOMMEND YOU TAKE THIS OFFERING OF 300 AS YOU DO NOT POSSESS THE REQUISITE BACKGROUND TO PASS THE COURSE.

More information

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011 CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture

More information

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable. CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,

More information

CSE 303 Winter 2008 Midterm Key

CSE 303 Winter 2008 Midterm Key CSE 303 Winter 2008 Midterm Key 1. [2 points] Give a Unix command line that will list all (and only) files that end with.h in the current working directory. Full credit: ls *.h Extra credit: ls a *.h (although

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science AUGUST 2011 EXAMINATIONS CSC 209H1Y Instructor: Daniel Zingaro Duration three hours PLEASE HAND IN Examination Aids: one two-sided 8.5x11

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! Gives

More information