1 Reminders Project 1 due tomorrow by 6:00 Office hours in 006 today at 4:30 Start thinking about project groups (3 people) for the rest of the quarter.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
SPLINT STATIC CHECKING TOOL Sripriya Subramanian 10/29/2002.
Computer Architecture CSCE 350
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Chapter 7: User-Defined Functions II
C Programming - Lecture 5
Informática II Prof. Dr. Gustavo Patiño MJ
CSE 451: Operating Systems Section 1. Why are you here? 9/30/102.
. Plab – Tirgul 2 Const, C Strings. Pointers int main() { int i,j; int *x; // x points to an integer i = 1; x = &i; j = *x; ijx 1.
1 CSE 451 Section Autumn 2004 Alex Moshchuk Office hours: Tue 1-2, Thu 4:30-5:30 Allen 218 (or lab)
CSE 451 Section Autumn 2005 Richard Dunn Office hours: WTh 3:30-4:20 Allen 216 (or lab)
1 C-strings String = null-terminated array of characters The null character ('\0') specifies where the string terminates in memory. Example: The string.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
Dynamically Allocated Arrays May 2, Quiz 5 Today.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
CS 61C L4 Structs (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #4: Strings & Structs
CSE 451 Section 4 Project 2 Design Considerations.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
CSE 451: Operating Systems Section 2 Interrupts, Syscalls, Virtual Machines, and Project 1.
1 Further C  Multiple source code file projects  Structs  The preprocessor  Pointers.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
C What you Know* Objective: To introduce some of the features of C. This assumes that you are familiar with C++ or java and concentrates on the features.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
Dynamically Allocated Arrays December 4, Skip the Rest of this PowerPoint.
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
Smashing the Stack Overview The Stack Region Buffer Overflow
Implementing System Calls CS552 Kartik Gopalan. CS552/BU/Spring2008 Steps in writing a system call 1.Create an entry for the system call in the kernel’s.
1 Homework HW5 due today Review a lot of things about allocation of storage that may not have been clear when we covered them in our initial pass Introduction.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Week 2. Functions: int max3(int num1, int num2, int num3) {int result; result = max(max(num1,num2),num3); return result; } //max3.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
Operating Systems Process Creation
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
1 CSE 451 Section 2: Processes, the shell, and system calls.
Chapter 16 Pointers and Arrays Pointers and Arrays We've seen examples of both of these in our LC-3 programs; now we'll see them in C. Pointer Address.
Announcements Remember what we talked on Tuesday in terms of Makefiles and phony targets. Don’t lose points for this! BTW, the.PHONY target can appear.
Lecture 7 Interrupt ,Trap and System Call
CSE 451 Section Autumn 2004 Alex Moshchuk Office hours: Tue 2-3, Thu 4:30-5:30 Allen 216 (or lab)
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
Chapter 7: User-Defined Functions II
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
CSE 451 Section 2: Processes, the shell, and system calls
CSCI206 - Computer Organization & Programming
CSC 253 Lecture 8.
CSC 253 Lecture 8.
Pointers, Dynamic Data, and Reference Types
C What you Know* Objective: To introduce some of the features of C. This assumes that you are familiar with C++ or java and concentrates on the features.
Process Programming Interface
October 9 Section Mike Swift
CSE 451 Section 2 – Winter 2006.
System calls What’s the exact process from user back to user?
System Calls David Ferry CSCI 3500 – Operating Systems
CSE 451 Section 2 - Spring 2005.
Reminders Project 1 due tomorrow at 5:00 pm
Implementing System Calls
Destructors, Copy Constructors & Copy Assignment Operators
Pointers, Dynamic Data, and Reference Types
Destructors, Copy Constructors & Copy Assignment Operators
Presentation transcript:

1 Reminders Project 1 due tomorrow by 6:00 Office hours in 006 today at 4:30 Start thinking about project groups (3 people) for the rest of the quarter Groups due by Tuesday noon ( After that we’ll pick a group for you Today: project 1 questions

2 Project 1 – issues C strings Copy_to/from_user and counters Syscalls: macros ; arguments Execvp, wait Other things??

3 C strings You only need to use: strncmp(src,dest,256) – compare strings, 0 if equal, not 0 o.w. Do not do str1 == str2!!! strtok: 1 st use: tok = strtok(buf, “delimiters”); Subsequent uses: tok = strtok(NULL, “delimiters”); fgets(buf, 256, stdin) – read a line (up to 256 chars) from stdin (or getline) (maybe) strncpy(dest, src, 256) – copy up to 256 chars from src to dest. (maybe) Allocate memory with malloc, free with free Fine to assume: A maximum length for a shell command (say, 256) Maximum number of arguments (say, 256 again)

4 Passing counters Do not printk the statistics in execcounts!!! Execcounts should pass count values to the shell The shell then prints out statistics Copying counters to userspace: Shell passes in something to hold data sys_execcounts fills the data in

5 Copying data to/from kernel Unsafe to directly access user pointers! long sys_gettimeofday(struct timeval *tv) { if (tv) { struct timeval ktv; do_gettimeofday(&ktv); if (copy_to_user(tv, &ktv, sizeof(ktv))) return -EFAULT; } return 0; } copy_to/from_user return amount of uncopied data

6 Syscalls Two ways to use one: Linux style: in : #define __NR_foo 292 static inline _syscall2(int, foo, int, arg1, char *, arg2) In userspace, just call foo(4,”test”); BSD style: in shell.c: #define __NR_foo 292 ret = syscall(__nr_foo, arg1, arg2);

7 How syscalls work In entry.S: ENTRY(system_call) pushl %eax # save orig_eax SAVE_ALL cmpl $(NR_syscalls),%eax jae badsys call *SYMBOL_NAME(sys_call_table)(,%eax,4) movl %eax,EAX(%esp) # save the return value restore_all: RESTORE_ALL

8 Execvp execvp: You must build an array of strings to pass to it Make sure the last thing in this array is NULL Make sure the array includes the program name

9 Wait wait(int *status) “man 2 wait” get information about it. “man wait” by default goes to the shell reference! What’s wrong with this code: int *status; wait(status); Fix??

10 Extern How do we access global variables defined in one file from another file?

11 Other things Check that every malloc has a matching free Check for all errors E.g. malloc returns NULL Frequently, global constant errno will be set Use perror(“error description”); to see what the error was. Don’t worry about architectures other than x86. Don’t worry about compiling the shell in vmware Compile on spinlock, transfer executable to vmware Q: “warning: implicit declaration of xyz” -- ??? A: Check include files