CS 350 : COMPUTER SYSTEM CONCEPTS SAMPLE TEST 2 (OPERATING SYSTEMS PART) Student s Name: MAXIMUM MARK: 100 Time allowed: 70 minutes

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

CS240: Programming in C

CS240: Programming in C

SE350: Operating Systems

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

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

Operating Systemss and Multicore Programming (1DT089)

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

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

What is a Process? Processes and Process Management Details for running a program

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

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.

Q1. State True/false with jusification if the answer is false:

CSI 402 Lecture 2 Working with Files (Text and Binary)

ENG120. Misc. Topics

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

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

Killing Zombies, Working, Sleeping, and Spawning Children

518 Lecture Notes Week 3

Inter-process communication (IPC)

Operating Systemss and Multicore Programming (1DT089)

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

Operating Systems. Lecture 05

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

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

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

Introduction to Processes

Assignment 1. Teaching Assistant: Michalis Pachilakis (

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

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

CSC 716 Advanced Operating System Fall 2007 Exam 1. Answer all the questions. The maximum credit for each question is as shown.

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

2009 S2 COMP File Operations

Operating Systems, laboratory exercises. List 2.

Lecture 7: file I/O, more Unix

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

Layers in a UNIX System. Create a new process. Processes in UNIX. fildescriptors streams pipe(2) labinstructions

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

Operating systems and concurrency - B03

Figure 1 Ring Structures

Process Management! Goals of this Lecture!

Lecture 8: Structs & File I/O

Processes. CS439: Principles of Computer Systems January 30, 2019

CSC 1600 Unix Processes. Goals of This Lecture

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Concurrency. Stefan D. Bruda. Winter 2018

CSCE 313: Intro to Computer Systems

Lecture 3 Process API in UNIX systems

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

Processes. CS439: Principles of Computer Systems January 24, 2018

Unix Processes 1 / 31

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Process Management 1

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

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Fall 2015 COMP Operating Systems. Lab #3

Operating System Structure

CSI Module 2: Processes

Operating Systems Lab

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.

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

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

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

UNIX Input/Output Buffering

COE518 Lecture Notes Week 2 (Sept. 12, 2011)

CSC209H Lecture 7. Dan Zingaro. February 25, 2015

Today: Process Management. The Big Picture So Far. What's in a Process? Example Process State in Memory

The Big Picture So Far. Today: Process Management

CS 550 Operating Systems Spring Inter Process Communication

* What are the different states for a task in an OS?

Announcement (1) sys.skku.edu is now available

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

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

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

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

PROGRAMMAZIONE I A.A. 2017/2018

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

Lecture 4 Threads. (chapter 4)

CS510 Operating System Foundations. Jonathan Walpole

UNIT I Linux Utilities

Creating a Shell or Command Interperter Program CSCI411 Lab

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

Processes. Johan Montelius KTH

CS240: Programming in C

Interprocess Communication E. Im

A process. the stack

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

EXPERIMENT NO : M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM,500GB HDD

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

CS 370 Operating Systems

2 Processes. 2 Processes. 2 Processes. 2.1 The Process Model. 2.1 The Process Model PROCESSES OPERATING SYSTEMS

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

Lecture 8: Unix Pipes and Signals (Feb 10, 2005) Yap

Transcription:

CS 350 : COMPUTER SYSTEM CONCEPTS SAMPLE TEST 2 (OPERATING SYSTEMS PART) Student s Name: MAXIMUM MARK: 100 Time allowed: 70 minutes Q1 (30 marks) NOTE: Unless otherwise stated, the questions are with reference to the C Programming Language and the UNIX operating System. (a) Give two reasons why we may need to use files in our programs. (b) Give two advantages of sequential access file (c) Give three limitations of sequential access files (d) What is the difference between each of the following: (i) fprintf() and fwrite() (ii) fwrite() and write() (iii) system call and library call 1

(e) (i) Given the following simple program, explain what the program does. (ii) Give a sample command line usage for the program. 1 /* 2 * sample test program - testprogram.c 3 */ 4 #include <stdio.h> 5 int main( int argc, char *argv[] ) 6 { 7 FILE *fptr1, *fptr2; 8 int c; 9 if ( argc!= 3 ) 10 printf( "wrong usage \n" ); 11 else 12 if ((fptr1 = fopen(argv[ 1 ], "r"))!= NULL) 13 if ((fptr2 = fopen(argv[2],"wr"))!= NULL) 14 { 15 fseek(fptr2, 0, SEEK_END); 16 while ((c = fgetc(fptr1))!= EOF) 17 fputc(c, fptr2); 18 } 19 else 20 printf("can't open file \"%s\"\n", argv[ 2 ] ); 21 else 22 printf("can't open file \"%s\"\n", argv[1]); 23 return 0; 24 } 2

Q2 (12 marks). For each of the following, indicate whether the assertion is TRUE or FALSE. s/n Assertion True or False 1 The functions rewind() and fseek() are similar, in that, they are both used to reposition the file position pointer. Also, rewind() can be implemented with appropriate use of fseek(), and vice versa. 2 Pipes can be used to communicate between processes that are not related 3 Signals can be used to communicated between processes on different machines 4 Semaphores can be used to solve the mutual exclusion problem. They can also be used to provide synchronization between processes. 5 Multiprogramming and timesharing are one and the same concept, in that, both aims at a more efficient utilization of the same computer system resource - the main memory 6 Pipes could be blocking or non-blocking, full duplex or half-duplex, but they can only be messageboundary non-preserving (and not message-boundary preserving) 7 At the time of creation, a process has access to the standard files: stdin, stdout and stderr. But these standard files can be redirected to other files in the course of program execution. 8 The exec family of system calls is used to overlay one process with another. Thus, the only way to get a child process to perform a different task from the parent is by use of an exec call. 9 With fread() (fwrite()), we typically read (or write) one element of an array of data structures at a time. However, we can actually read (write) multiple elements with one call to fread() (fwrite() ). 10 The operating system and other system programs operate in kernel (protected) mode, while all other programs operate in user mode. 11 A zombie process is a major problem in operating systems, since a zombie process consumes system resources, and the zombie cannot be removed from the system. 12 The system calls wait() and waitpid() are similar in the sense that both of them can be used to wait for a process. Therefore, one can always be used in place of the other. Q3 (30 marks) (a) Given that we have a program file imageserver.c. We compile this to produce an executable file, called imageserver. At some other stage, we talk of the "imageserver process". (i) Give two differences between imageserver (the executable program), and imageserver, the process. (ii) What is the relationship between the two? (b) (i) Using a diagram explain the possible states that a process can be, indicating the transition between states. (ii) Give one reason for each of the allowable transitions in your diagram. 3

(c) When the following program is executed, the result will be a process tree, which may vary from one run to the other. (i) Using a diagram, sketch two of the possible process trees than can result if the program were to be executed. (ii) Very briefly, explain why we could have different possible process trees for the same program. [You can assume process ID's are integer numbers from 5, 6, 7,. Assume no error during the fork() system call.] 1 #include <stdio.h> 2 #include <sys/types.h> 3 #include <unistd.h> 4 int main() 5 { 6 int k =0; 7 pid_t PID; 8 PID=fork(); 9 if (PID %2!= 0 ) 10 break; 11 else 12 printf("i am %ld, the child of %ld, (long)getpid(), (long)getppid() ); 13 return 0; 14 } 4

Q4 (28 marks) (a) Signals and pipes are two mechanisms that can be used to communicate between processes. (i) List two advantages of using signals for inter-process communication (ii) List two limitations in using signals for inter-process communication (iii) List two advantages of using pipes for inter-process communication (iv) List two limitations in using pipes for inter-process communication (b) (i) Give one difference between SIGSTOP (the stop signal) and SIGKILL (the kill signal) (ii) Give one similarity between SIGSTOP (the stop signal) and SIGKILL (the kill signal) (d) Two major problems with most solutions to the critical section problem are busy waiting and priority inversion. (i) Very briefly, explain what busy waiting means, in the context of operating systems. (ii) Very briefly, explain what priority inversion means, in the context of operating systems. (ii) How can these problems be resolved? 5