Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Week 5 - Wednesday.  What did we talk about last time?  Arrays.
Week 7 - Friday.  What did we talk about last time?  Allocating 2D arrays.
Discussion Week 5 TA: Kyle Dewey. Overview HW 3.10 and 6.2 review Binary formats System call execution in NACHOS Memory management in NACHOS I/O in NACHOS.
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
CS 300 – Lecture 23 Intro to Computer Architecture / Assembly Language Virtual Memory Pipelining.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
C and Data Structures Baojian Hua
7/13/20151 Topic 3: Run-Time Environment Memory Model Activation Record Call Convention Storage Allocation Runtime Stack and Heap Garbage Collection.
Memory Layout C and Data Structures Baojian Hua
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Software Development and Software Loading in Embedded Systems.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Week 4 - Wednesday.  What did we talk about last time?  Evil: break, continue, goto  System calls  Functions.
Chapter 3 Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
System Calls 1.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Section 3.1: Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Processes and OS basics. RHS – SOC 2 OS Basics An Operating System (OS) is essentially an abstraction of a computer As a user or programmer, I do not.
The Structure of Processes. What is a Process? an instance of running program Program vs process(task) Program : just a passive collection of instructions.
CS 346 – Chapter 1 Operating system – definition Responsibilities What we find in computer systems Review of –Instruction execution –Compile – link – load.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Topic 2d High-Level languages and Systems Software
Guide To UNIX Using Linux Third Edition Chapter 8: Exploring the UNIX/Linux Utilities.
Chapter 4 Memory Management Virtual Memory.
Processes Introduction to Operating Systems: Module 3.
1 Chapter 4 Processes R. C. Chang. 2 Linux Processes n Each process is represented by a task_struct data structure (task and process are terms that Linux.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
ICOM Noack Memory management Virtual memory Paging and segmentation Demand paging Memory management hardware.
1 Pintos Virtual Memory Management Project (CS3204 Spring 2006 VT) Yi Ma.
Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Announcements Partial Credit Due Date for Assignment 2 now due on Sat, Feb 27 I always seem to be behind and get tons of daily. If you me and.
CS161 – Design and Architecture of Computer
CSC 482/582: Computer Security
Week 4 - Friday CS222.
CS161 – Design and Architecture of Computer
Process Memory COMP 40: Machine Structure and
Programs – Loading and Running an Executable
Linux Userspace Process Memory Layout
Program Execution in Linux
Process Realization In OS
Software Development with uMPS
CIT 480: Securing Computer Systems
Topic 2e High-Level languages and Systems Software
Lecture 5: Process Creation
Operation System Program 4
Computer Organization & Compilation Process
More examples How many processes does this piece of code create?
Memory Allocation CS 217.
Operating System Chapter 7. Memory Management
Embedded System Development Lecture 13 4/11/2007
Programs – Loading and Running an Executable
Program Execution in Linux
CSE 153 Design of Operating Systems Winter 2019
Computer Organization & Compilation Process
Week 7 - Friday CS222.
Presentation transcript:

Week 4 - Friday

 What did we talk about last time?  Some extra systems programming stuff  Scope

Unix never says "please." Rob Pike Unix never says "please." Rob Pike  It also never says:  "Thank you"  "You're welcome"  "I'm sorry"  "Are you sure you want to do that?"

 All real programs are written in multiple files  To compile such files, do the following  Create a header file (with a.h extension) for every file that contains prototypes for functions you're going to use in other files  #include those header files in every file that uses them  When you run gcc, put all the.c files needed on the line at the same time

 Your main() function and core program is in a file called program.c  You have files called networking.c and graphics.c that have networking and graphics functions that your program uses  You should have headers called networking.h and graphics.h (names don't have to match, but it is better if they do)  At the top of program.c should be:  To run gcc you type: #include "networking.h" #include "graphics.h" #include "networking.h" #include "graphics.h" gcc program.c networking.c graphics.c -o program

 You can compile a file into object code without linking it into an executable  Produces a.o file  That way, you can compile all the pieces separately and then link them later  This can be more efficient if you are updating some of the code but not all of it  To compile but not link, use gcc -c  We could compile the previous example as follows gcc –c program.c gcc –c networking.c gcc –c graphics.c gcc program.o networking.o graphics.o -o program gcc –c program.c gcc –c networking.c gcc –c graphics.c gcc program.o networking.o graphics.o -o program

 Now that we're talking about compiling multiple files, a makefile really makes (ha, ha) sense all: program program: program.o networking.o graphics.o gcc program.o networking.o graphics.o -o program program.o: program.c networking.h graphics.h gcc –c program.c networking.o: networking.c gcc –c networking.c graphics.o: graphics.c gcc –c graphics.c clean: rm -f *.o program all: program program: program.o networking.o graphics.o gcc program.o networking.o graphics.o -o program program.o: program.c networking.h graphics.h gcc –c program.c networking.o: networking.c gcc –c networking.c graphics.o: graphics.c gcc –c graphics.c clean: rm -f *.o program

 Recall that a process is a running program  Multiple copies of a single program can be running as different processes  A program is a binary file (generated by the compiler)  Formats used to be:  Assembly output (where the name a.out comes from)  COFF (Common Object File Format)  Now they are usually ELF (Executable and Linking Format)  Details about binary formats are more interesting when you're writing a compiler

 Every running process has a process ID (PID)  You can find out the PID of the currently executing code by calling the getpid() function  Every process also has a parent process (which has a parent PID)  Get that by calling getppid()  The parent is the process that created the current process  This parent-child relationship forms a tree all the way back to the first process init, which always has PID 1

 Layout for 32-bit architecture  Could only address 4GB  Modern layouts often have random offsets for stack, heap, and memory mapping for security reasons Text Data BSS Heap Memory Mapping Stack Kernel Space 1GB 3GB 0xc x x x Only for Linux kernel Memory for function calls Addresses for memory mapped files Dynamically allocated data Uninitialized globals Initialized globals Program code

 Those addresses (from 0 to 4GB) are virtual addresses  Each program sees an address space stretching from 0 to 4GB  The OS transparently manages how those addresses are mapped to physical memory  The virtual address space is divided up into pages  Each page can be in memory or sitting on disk  Pages are typically moved into memory only when needed

 It isolates processes from each other  Since they have different address spaces, it is harder for one program to read the data out of another  Processes can share the same memory without inadvertently trampling on each other  Since paging is controlled by the OS, pages can be marked read-only  Programmers don't need to worry about the actual layout of memory  Programs can load faster because only part of them needs to be put into RAM

 ps gives a snapshot of the current processes running  top gives repeatedly updated information about the processes running  The kill command lets you end a process  You have to have sufficiently high privileges to do so

 Arrays

 Read K&R chapter 5  Keep working on Project 2