Reminders Project 1 due tomorrow at 5:00 pm

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

Recitation By yzhuang, sseshadr. Agenda Debugging practices – GDB – Valgrind – Strace Errors and Wrappers – System call return values and wrappers – Uninitialization.
C Lab 3 C Arraylist Implementation. Goals ●Review ○ Referencing/Dereferencing ○ Free ●realloc and memmove ●ArrayList ●Debugging with GDB.
CSE 451: Operating Systems Section 2 Shells and System Calls.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
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 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.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Concurrency Sharing of resources in the same time frame Apparent concurrency is sharing the same CPU, memory, or I/O device Real concurrency is sharing.
CSE 451 Section 4 Project 2 Design Considerations.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
CSE 451: Operating Systems Section 2 Interrupts, Syscalls, Virtual Machines, and Project 1.
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Minishell InKwan Yu Topics Unix System calls waitpid() pipe() dup2() C function calls strtok() strcmp() Minishell Software Enginnering.
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.
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.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
CSE 451: Operating Systems Section 3: Project 0 recap, Project 1.
Operating Systems Process Creation
Recitation 11 (Nov. 22) Outline Lab 6: interposition test Error handling I/O practice problem Reminders Lab 6: Due Tuesday Minglong Shao
Process Management Azzam Mourad COEN 346.
Recitation 9: Error Handling, I/O, Man Anubhav Gupta Section D.
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
1 CSE 451 Section 2: Processes, the shell, and system calls.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
CSE 451 Section Autumn 2004 Alex Moshchuk Office hours: Tue 2-3, Thu 4:30-5:30 Allen 216 (or lab)
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
CSE 451 Section #3 Project 0 Recap Project 1 Overview
Error handling I/O Man pages
Buffer Overflow Buffer overflows are possible because C doesn’t check array boundaries Buffer overflows are dangerous because buffers for user input are.
YongChul Kwon CSE451 Section 1: Spring 2006 YongChul Kwon
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
CSE 451 Section 2: Processes, the shell, and system calls
Homework Reading Machine Projects Labs PAL, pp ,
CSCI206 - Computer Organization & Programming
CSC 253 Lecture 8.
Lecture 5: Process Creation
Fork and Exec Unix Model
CSC 253 Lecture 8.
Processes in Unix, Linux, and Windows
Assembly Language Programming II: C Compiler Calling Sequences
Discussions on HW2 Objectives
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.
File Input and Output.
Programming in C Miscellaneous Topics.
Process Programming Interface
October 9 Section Mike Swift
Programming Project #1 Command Shell
CSE 451 Section 2 – Winter 2006.
System calls What’s the exact process from user back to user?
Programming in C Miscellaneous Topics.
System Calls David Ferry CSCI 3500 – Operating Systems
Tutorial: The Programming Interface
Programming Project #1 Fork and Command Shell
Chapter 16 Pointers and Arrays
CSE 451 Section 2 - Spring 2005.
Discussions on HW2 Objectives
Lecture 6: Multiprogramming and Context Switching
C++ Pointers and Strings
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
EECE.4810/EECE.5730 Operating Systems
C Programming - Lecture 5
EECE.4810/EECE.5730 Operating Systems
Intro to the Shell with Fork, Exec, Wait
Presentation transcript:

Reminders Project 1 due tomorrow at 5:00 pm Homework 2 out, due next Wednesday Start thinking about project groups (3 people) for the rest of the quarter Today: project 1 questions

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

C strings You only need to use: Fine to assume: strncmp(src,dest,256) – compare strings, 0 if equal, not 0 o.w. strtok: 1st 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)

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 This could be a pointer to a struct, an array, or four pointers to ints. execcounts fills the data in

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

Syscalls Two ways to use one: Linux style: #define __NR_foo 292 in <asm/unistd.h>: #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: ret = syscall(__nr_foo, arg1, arg2);

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

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!

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

Code quality What’s wrong with this: How do we fix this? char * buffer; buffer = malloc(100); strcpy(buffer, param); How do we fix this?

Debugging #define MYDEBUG #ifdef MYDEBUG #define DEBUG(x) x #else #endif … DEBUG(printf(“debug output“));

Debugging 2 Just for printing: works for both for kernel and userspace #ifdef MYDEBUG # ifdef __KERNEL__ /* This one if debugging is on, and kernel space */ # define PDEBUG(fmt, args...) printk(“myprg: " fmt, ## args) # else /* This one for user space */ # define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args) # endif #else # define PDEBUG(fmt, args...) /* not debugging: nothing */ #endif works for both for kernel and userspace To use: PDEBUG(“Testing two numbers: %d and %d\n”, num, num2);

Things to check Check that every malloc has a matching free Check for errors E.g. execvp returns -1, malloc returns NULL Frequently, global constant errno will be set Use perror(“error description”); to see what the error was.

Fork How does it work? Any problems with it?

UNIX startup Kernel only creates one process: init (pid 1) Never creates any other processes init spawns other processes using fork, exec, etc. E.g. init creates a bunch of getty processes One for each terminal Each outputs “login: “ prompt, gets input, execs login process Login prompts for a password, execs shell if it’s ok Off-topic: why is cd a built-in command in your shell? init->getty x… ->login->bash,csh…

A UNIX Process

Same Process after fork