Help Session 2. Programming Assignment 2

Similar documents
File IO and command line input CSE 2451

Introduction to file management

Standard File Pointers

CS240: Programming in C

File Access. FILE * fopen(const char *name, const char * mode);

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre

CSC 1600 Unix Processes. Goals of This Lecture

CSC209 Review. Yeah! We made it!

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

Day14 A. Young W. Lim Tue. Young W. Lim Day14 A Tue 1 / 15

Lab # 4. Files & Queues in C

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Interacting with Unix

File I/O. Arash Rafiey. November 7, 2017

C for Engineers and Scientists: An Interpretive Approach. Chapter 14: File Processing

This code has a bug that allows a hacker to take control of its execution and run evilfunc().

Operating System Structure

CS240: Programming in C

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.

C-Refresher: Session 10 Disk IO

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;

Fundamentals of Programming & Procedural Programming

Process Management! Goals of this Lecture!

Parents and Children

Fall 2015 COMP Operating Systems. Lab #3

Input/Output and the Operating Systems

Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Q & A (1) Where were string literals stored? Virtual Address. SSE2033: System Software Experiment 2 Spring 2016 Jin-Soo Kim

SE350: Operating Systems

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

7/21/ FILE INPUT / OUTPUT. Dong-Chul Kim BioMeCIS UTA

CSC209H Lecture 6. Dan Zingaro. February 11, 2015

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Process Management 1

fork System-Level Function

Procedural Programming

HIGH LEVEL FILE PROCESSING

Princeton University Computer Science 217: Introduction to Programming Systems. Process Management

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

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

File I/O, Project 1: List ADT. Bryce Boe 2013/07/02 CS24, Summer 2013 C

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

Princeton University. Computer Science 217: Introduction to Programming Systems. Process Management

Fundamentals of Programming. Lecture 10 Hamed Rasifard

Processes: Introduction. CS 241 February 13, 2012

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

Process Management! Goals of this Lecture!

Topic 8: I/O. Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional)

Engineering program development 7. Edited by Péter Vass

Memory Layout, File I/O. Bryce Boe 2013/06/27 CS24, Summer 2013 C

Unix Processes 1 / 31

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

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

CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files

Input / Output Functions

Princeton University Computer Science 217: Introduction to Programming Systems. Process Management

Introduction to C Recursion, sorting algorithms, files

CSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS

System Software Experiment 1 Lecture 7

Process Management 1

Lesson 2. process id = 1000 text data i = 5 pid = 1200

CSCB09: Software Tools and Systems Programming. Bianca Schroeder IC 460

Preview from Notesale.co.uk Page 2 of 79

EM108 Software Development for Engineers

Files. Programs and data are stored on disk in structures called files Examples. a.out binary file lab1.c - text file term-paper.

UNIX Processes. by Armin R. Mikler. 1: Introduction

Operating Systems Lab

ปฏ บ ต การ #3. A Simple Shell Interpreter

C Basics And Concepts Input And Output

Operating systems and concurrency - B03

Introduction to Processes

Discussion of Assignments 2. Line buffered vs. full buffered I/O. Some often encountered issues in the submissions.

The Programming Interface

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

Standard C Library Functions

UNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

structs as arguments

File (1A) Young Won Lim 11/25/16

Standard I/O in C, Computer System and programming in C

CMPE-013/L. File I/O. File Processing. Gabriel Hugh Elkaim Winter File Processing. Files and Streams. Outline.

Process management 1

UNIT IV-2. The I/O library functions can be classified into two broad categories:

Data File and File Handling

CS 261 Fall Mike Lam, Professor. Structs and I/O

2009 S2 COMP File Operations

C programming basics T3-1 -

University of Washington What is a process?

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

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Programming for Engineers Arrays

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

Exceptional Control Flow Part I

LAB 1: C PRIMER CS444/544 WENJIN HU JAN 16TH, 2009

Operating System Labs. Yuanbin Wu

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Programming Assignment #1: A Simple Shell

Transcription:

Help Session 2 Programming Assignment 2

Outline Learn how to use the following fork() execlp() wait() system() File operations

Assignment Information Two executables will be needed ParentProgram Main program, that opens, reads and closes the file, forks child processes. Executor Executes the command received as an argument using system() and returns the status of the execution.

ParentProgram.c Can take one or no command line arguments. The argument if passed should be the name of the text file containing a list of commands to be executed. The objective is the ParentProgram.c should open the file provided in the argument, or the default file textfile.txt, and read the content of the file as a single string, and close the file. After that, it should parse the string into separate commands, and for each command, should fork a separate child process which runs Executor.c

fork()

fork() Generates an exact copy of parent process except for the value it returns In a child process, fork() returns zero In the parent process it will return the child s process ID Any process can retrieve its process ID with getpid(), and its parent process ID with getppid() Syntax: pid_t fork();

wait() Makes Initiator wait until the child has been entirely executed Use WIFEXITED() to check whether child process has completed its execution Use WEXITSTATUS() to retrieve return value of child process Syntax pid_t wait(int* stat_loc);

execlp() Executes a new program within a child process Arguments passed the name of the executable and filename like./executor, Executor.c Also pass any needed command line arguments as parameters Terminate list of arguments with NULL Syntax int execlp(./executable_name, Filename, const char *arg,..., NULL);

system() This is a function available to execute the Operating System commands. The function is obviously Operating System dependent. Syntax: int system(const char* command);

Demo 1

File Operations We need three functions for this particular assignment. They are: fopen() fgets() fclose()

fopen() Used to open a file, whose name is given as the argument. It returns a pointer to the opened file. Syntax: FILE * fp = fopen(const char *filename, const char *mode)

fgets() It is used to read content from a file. Syntax char *fgets(char *str, int n, FILE *stream) It reads n-1 characters, till the newline character is encountered, or til end of line character, whichever comes first.

fclose() Closes the stream to the file. Buffers are flushed. Syntax int fclose(file *stream)

Demo 2

Project Choices Teams: Team sizes of 2 or 3. You choose. All of them must put in their share of effort. Choice A: Research a technical topic of current interest. A list of topics will be available. The topic needs to be pre-approved. Choice B: An embedded/iot development project. Research the aim, platform, obtain hardware/software. Need a critical design evaluation and a demo.

Project Deadlines 1. Team composition and idea proposal, Tu 2/20/18 2. Progress report Tue 3/27/18 3. Preliminary report (slides/posters* as needed) Tue 4/24/18 4. Final report (and demos* for Option B) Tue 5/1/18 Note: Posters and demos will be scheduled later depending on other departmental events scheduled. Dates subject to some adjustment.

Option A: Research a technical topic A list of topics will be available Must be of current interest and related to operating systems You will research using in-depth research/industrial publications and news articles. You will learn about the state of the art and current technological trends. A formal report is the specified format will be needed. A presentation using slides/poster will also be needed.

Option B: An embedded/iot system Project must involve a platform (such as a Raspberry Pi) which will communicate with at least one other computer and with at last one sensor. You will specify the project objective, select the appropriate platform, hardware/software needed. Your proposal must include a justification of the choices. After you have built your system, will evaluate for at least one attribute (potential security holes, power consumption, available resolution or reliability) A report, a demonstration, and a set of slides will be needed.