Matt Ramsay CS 375 EXAM 2 Part 1

Similar documents
Operating Systems Lab

CS240: Programming in C

Contents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO)

CSC 271 Software I: Utilities and Internals

CSC209H Lecture 6. Dan Zingaro. February 11, 2015

CS Operating Systems Lab 3: UNIX Processes

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

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

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

UNIX System Calls. Sys Calls versus Library Func

Process Creation in UNIX

CSC 1600 Unix Processes. Goals of This Lecture

Figure 1 Ring Structures

everything is a file main.c a.out /dev/sda1 /dev/tty2 /proc/cpuinfo file descriptor int

SOFTWARE ARCHITECTURE 3. SHELL

A: We see the ps auxw execute and print on screen. The program holds the command in buffer then it is printed on screen.

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

프로세스간통신 (Interprocess communication) i 숙명여대창병모

Lab 5: Inter-Process Communication

CS240: Programming in C

What is a Process. Preview. What is a Process. What is a Process. Process Instruction Cycle. Process Instruction Cycle 3/14/2018.

Chapter 1. Introduction

System Programming. Introduction to Unix

Operating System Labs. Yuanbin Wu

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering

CSE 333 SECTION 3. POSIX I/O Functions

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

Unix Basics Compiling and Using. CMPT 300 Operating Systems I Summer Segment 2: Unix Basics. Melissa O Neill

518 Lecture Notes Week 3

Pipes. Pipes Implement a FIFO. Pipes (cont d) SWE 545. Pipes. A FIFO (First In, First Out) buffer is like a. Pipes are uni-directional

Parents and Children

UNIX System Programming. Overview. 1. A UNIX System. 2. Processes (review) 2.1. Context. Pipes/FIFOs

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

CITS2002 Systems Programming. Creating a new process using fork() 1 next CITS2002 CITS2002 schedule

vector<process*> Delete(vector<process*> DeleteQ, int ID); vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW);

Computer Systems Assignment 2: Fork and Threads Package

Concurrency. Stefan D. Bruda. Winter 2018

Lecture 21 Systems Programming in C

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

MMAP AND PIPE. UNIX Programming 2015 Fall by Euiseong Seo

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

CSE 333 SECTION 3. POSIX I/O Functions

Recitation 8: Tshlab + VM

File Descriptors and Piping

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

Gabrielle Evaristo CSE 460. Lab Shared Memory

CS Operating system Summer Midterm I -- July 11, 2017 You have 115 min (10:00am-11:55pm). Good Luck!

System Calls and I/O Appendix. Copyright : University of Illinois CS 241 Staff 1

Process Turnaround Time Total Wait Time P 1 12 ms 0 ms P 2 21 ms 12 ms P 3 23 ms 18 ms P 4 20 ms 17 ms

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

System Programming. Process Control II

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)

Operating System Labs. Yuanbin Wu

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

CS240: Programming in C

File: /home/young/mywork/7.cordic_accuracy/if.ghdl/ghdlif.print Page 1 of 15

ECE 650 Systems Programming & Engineering. Spring 2018

CS 3013 Operating Systems WPI, A Term Assigned: Friday, August 31, 2007 Due: Monday, September 17, 2007

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

File: /home/young/mywork/7.cordic_accuracy/ghdl/print.file Page 1 of 13

Operating Systems. Lecture 05

System- Level I/O. Andrew Case. Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

OPERATING SYSTEMS: Lesson 2: Operating System Services

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Exam 1 Questions (document version 1.1)

Computer Science & Engineering Department I. I. T. Kharagpur

ECE322 Systems Programming Project 2: Networking with Matrix Multiplication in C Grant Kimes 12/16/15

System Programming. Process Control III

SE350: Operating Systems

Chapter 3 Processes we will completely ignore threads today

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

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Multi-Process Programming in C

Unix Processes 1 / 31

Contents. PA1 review and introduction to PA2. IPC (Inter-Process Communication) Exercise. I/O redirection Pipes FIFOs

Final Precept: Ish. Slides Originally Prepared by: Wonho Kim

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Chapter 10. The UNIX System Interface

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

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.

OPERATING SYSTEMS: Lesson 12: Directories

File and Directories. Advanced Programming in the UNIX Environment

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

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

Files and File System

Compile and execute fifo1.cpp listed above. Try the Balady's anomaly examples discussed in class. Did you observe the Belady's anomaly?

Interprocess Communication E. Im

Why files? 1. Storing a large amount of data 2. Long-term data retention 3. Access to the various processes in parallel

Process management 1

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

Shared Memory Memory mapped files

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

POSIX Semaphores. Operations on semaphores (taken from the Linux man page)

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Midterm Exam Questions (document version 1.1)

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Do not turn the page until 5:00.

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

Transcription:

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 of 3 between 15003 and 30000 add to 112507500 This total written to /home/mr56/tmp/file8772.out Multiples of 3 between 30003 and 45000 add to 187507500 This total written to /home/mr56/tmp/file8773.out Multiples of 3 between 45003 and 60000 add to 262507500 This total written to /home/mr56/tmp/file8774.out Multiples of 3 between 60003 and 75000 add to 337507500 This total written to /home/mr56/tmp/file8775.out First fifth added to 37507500 Second fifth added to 112507500 Third fifth added to 187507500 Fourth fifth added to 262507500 Last fifth added to 337507500 Total added to 937537500 Parent Code: #include <iostream> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <libgen.h> #include <sys/stat.h> #include <sys/types.h>

#include <fcntl.h> #include <sys/wait.h> #include <dirent.h> #include <errno.h> #include <pwd.h> #include <grp.h> #include <time.h> using namespace std; int main(int argc, char *argv[]) if(argc!= 3) cout << "You didn't enter enough commmand line arguments, you are a fuck-stick\n"; DIR *dp; // file descriptor struct dirent *de; // another file descriptor struct stat statbuf; // struct for stat command int total = 0; // sum of numbers char inputsum[16] = ' '; // temp sum int blah, beread, fd; // file desciptors and counters int lower = atoi(argv[1]); // lower bound int upper = atoi(argv[2]); // upper bound int division = (upper-lower)/5; // divide by 5 if((upper-lower)%5!= 0) division++; char path[16] = ' '; // strings to save file names char blah1[27] = ' '; char blah2[27] = ' '; char blah3[27] = ' '; char blah4[27] = ' '; char blah5[27] = ' '; char first[5] = ' '; char second[5] = ' '; char third[5] = ' '; char fourth[5] = ' '; char fifth[5] = ' '; char firstb[5] = ' '; char secondb[5] = ' '; char thirdb[5] = ' '; char fourthb[5] = ' '; char fifthb[5] = ' ';

char file1[35] = ' '; char file2[35] = ' '; char file3[35] = ' '; char file4[35] = ' '; char file5[35] = ' '; pid_t pid1, pid2, pid3, pid4, pid5; //fork file descriptors sprintf(path, "/home/mr56/tmp/*"); //writing proper names into strings sprintf(first,"%d",lower); sprintf(firstb,"%d",division); sprintf(second,"%d",(division+1)); sprintf(secondb,"%d",(division*2)); sprintf(third,"%d",((division*2)+1)); sprintf(thirdb,"%d",(division*3)); sprintf(fourth,"%d",((division*3)+1)); sprintf(fourthb,"%d",(division*4)); sprintf(fifth,"%d",((division*4)+1)); sprintf(fifthb,"%d",upper); pid1 = fork(); // fork first process if(pid1 == 0) execl("exam2", "exam2", first, firstb, 0); // exec child pid2 = fork(); // fork second process if(pid2 == 0) execl("exam2", "exam2", second, secondb, 0); // exec child pid3 = fork(); // fork third process if(pid3 == 0) execl("exam2", "exam2", third, thirdb, 0); // exec child pid4 = fork(); // fork fourth process if(pid4 == 0) execl("exam2", "exam2", fourth, fourthb, 0); //exec child pid5 = fork(); // fork fifth process if(pid5 == 0)

execl("exam2", "exams", fifth, fifthb, 0); // exec child int stat_val; pid_t child_pid; pid1 = wait(&stat_val); // wait for children to finish pid2 = wait(&stat_val); pid3 = wait(&stat_val); pid4 = wait(&stat_val); pid5 = wait(&stat_val); if((dp = opendir("/home/mr56/tmp")) == NULL) //open directory cout << "Error opening /home/mr56/tmp" << endl; de = readdir(dp); // read first two files '.' and '..' de = readdir(dp); // and disregard if((de = readdir(dp))!= NULL) // save files from children to file1 - file 5 sprintf(file1, "%s", de->d_name); if((de = readdir(dp))!= NULL) sprintf(file2, "%s", de->d_name); if((de = readdir(dp))!= NULL) sprintf(file3, "%s", de->d_name); if((de = readdir(dp))!= NULL)

sprintf(file4, "%s", de->d_name); if((de = readdir(dp))!= NULL) sprintf(file5, "%s", de->d_name); closedir(dp); close directory sprintf(blah1, "/home/mr56/tmp/%s", file1); fd = open(blah1, O_RDONLY); //open first file beread = read(fd, inputsum, 12); // read partial sum blah = atoi(inputsum); //change to int cout << endl << "First fifth added to " << blah << endl; // add to total //close file //same for next four files sprintf(blah2, "/home/mr56/tmp/%s", file2); fd = open(blah2, O_RDONLY); beread = read(fd, inputsum, 12); blah = atoi(inputsum); cout << "Second fifth added to " << blah << endl; sprintf(blah3, "/home/mr56/tmp/%s", file3); fd = open(blah3, O_RDONLY); beread = read(fd, inputsum, 12); blah = atoi(inputsum); cout << "Third fifth added to " << blah << endl; sprintf(blah4, "/home/mr56/tmp/%s", file4); fd = open(blah4, O_RDONLY); beread = read(fd, inputsum, 12);

blah = atoi(inputsum); cout << "Fourth fifth added to " << blah << endl; sprintf(blah5, "/home/mr56/tmp/%s", file5); fd = open(blah5, O_RDONLY); beread = read(fd, inputsum, 12); blah = atoi(inputsum); cout << "Last fifth added to " << blah << endl; cout << "Total added to " << total << endl << endl; sprintf(path, "/home/mr56/tmp/%s", file1); // delete files made by children sprintf(path, "/home/mr56/tmp/%s", file2); sprintf(path, "/home/mr56/tmp/%s", file3); sprintf(path, "/home/mr56/tmp/%s", file4); sprintf(path, "/home/mr56/tmp/%s", file5); Child Code: #include <iostream> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <libgen.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <sys/wait.h> using namespace std; int main(int argc, char *argv[]) if(argc!= 3)

cout << "You didn't enter enough commmand line arguments, you are a fuck-stick\n"; char filename[35] = ' '; // string for filename char outputsum[20] = ' '; // string for number int fd, written; // file descriptors int sum = 0; // sum int id = getpid(); // id of child int lower = atoi(argv[1]); // lower bound int upper = atoi(argv[2]); // upper bound sprintf(filename,"/home/mr56/tmp/file%d.out",id); // make filename string if(lower < 3) // start at first multiple of three in range lower = 3; if(lower % 3 == 1) lower += 2; else if(lower % 3 == 2) lower += 1; for(int i = lower; i <= upper; i++) // loop for sum sum += i; i += 2; sprintf(outputsum, "%d", sum); //write sum to string fd = open(filename, O_RDWR O_CREAT); // open file and creates if not there chmod(filename, 777); // make file writeable written = write(fd, outputsum, 20); //write total to file //close file chmod(filename, 777); // unnesessary crap // output cout << endl << endl << "Multiples of 3 between " << lower << " and " << upper << " add to " << sum << endl; cout << "This total written to " << filename << endl;

Makefile: finish:parent.o exam2.o g++ -o parent parent.cpp g++ -o exam2 exam2.cpp parent.o:parent.cpp g++ -c parent.cpp exam2.o:exam2.cpp g++ -c exam2.cpp