Outline Unix Architecture Vi Fork Pthread. UNIX Architecture.

Slides:



Advertisements
Similar presentations
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 pThreads.
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 6: Threads Chapter 4.
PTHREADS These notes are from LLNL Pthreads Tutorial
Computer Architecture II 1 Computer architecture II Programming: POSIX Threads OpenMP.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
1 CS 333 Introduction to Operating Systems Class 3 – Threads & Concurrency Jonathan Walpole Computer Science Portland State University.
Fork Fork is used to create a child process. Most network servers under Unix are written this way Concurrent server: parent accepts the connection, forks.
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Advanced Programming in the UNIX Environment Hop Lee.
02/02/2004CSCI 315 Operating Systems Design1 Threads Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Processes, Threads, SMP, and Microkernels
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
OPERATIONS ON PROCESSES Process creation fork() exec() The argument vector Process deletion kill() signal()
Project 2 Data Communication Spring 2010, ICE Stephen Kim, Ph.D.
Unix 教學. Unix-like System Linux FreeBSD Solaris Mac OS X …
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 4: Threads.
Chapter 4 Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
PRINCIPLES OF OPERATING SYSTEMS Lecture 6: Processes CPSC 457, Spring 2015 May 21, 2015 M. Reza Zakerinasab Department of Computer Science, University.
Operating Systems Chapter 2
Creating and Executing Processes
Operating Systems CMPSC 473 Multi-threading models Tutorial on pthreads Lecture 10: September Instructor: Bhuvan Urgaonkar.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
CS333 Intro to Operating Systems Jonathan Walpole.
Unix 教學. Unix-like System Linux FreeBSD Solaris Mac OS X …
Lecture 7: POSIX Threads - Pthreads. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
Pthreads.
Shan Gao Fall 2007 Department of Computer Science Georgia State University.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Outline n Overview n Multithreading.
CS307 Operating Systems Threads Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2011.
Process Management Azzam Mourad COEN 346.
Threads Dr. Yingwu Zhu. Threaded Applications Web browsers: display and data retrieval Web servers Many others.
Now that you know the pthread API…  How do you create threads?  How do you pass different values to them?  How do you return values from threads? 
Unix 教學 1. Unix-like System  Linux  FreeBSD  Solaris  Mac OS X  … 2.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
CS431-cotter1 Linux Programming, Processes, and Threads Man pages (fork, clone, execve, pthread_create) The Linux Programming Interface – Kerrisk, No Starch,
POSIX Threads Loren Stroup EEL 6897 Software Development for R-T Engineering Systems.
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
OPERATING SYSTEMS 3 - PROCESSES PIETER HARTEL 1. Principle of concurrency - giving a process the illusion that it owns the whole machine  A process has:
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Thread Programming 김 도 형김 도 형. 2 Table of Contents  What is a Threads?  Designing Threaded Programs  Synchronizing Threads  Managing Threads.
Tutorial 4. In this tutorial session we’ll see Threads.
Unix 教學.
Lecture 5 : Pthread Programming
Lab. 2 (April 15th) Modify the multithreaded JAVA code we practiced in Lab. 1 to C code with pthread library. Pthread library works in UNIX environment.
Protection of System Resources
CS399 New Beginnings Jonathan Walpole.
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
PTHREADS These notes are from LLNL Pthreads Tutorial
Operating Systems Lecture 13.
Fork and Exec Unix Model
Jonathan Walpole Computer Science Portland State University
Operating Systems Lecture 14.
CS510 Operating System Foundations
Jonathan Walpole Computer Science Portland State University
Tutorial 3 Tutorial 3.
Operating System Concepts
Programming with Shared Memory
Jonathan Walpole Computer Science Portland State University
Programming with Shared Memory
Tutorial 4.
Section 2 Processes January 27rd, 2017 Taught by Joshua Don.
Outline Chapter 3: Processes Chapter 4: Threads So far - Next -
Computer Architecture Multi-threaded Matrix Multiply
EECE.4810/EECE.5730 Operating Systems
Shared Memory Programming with Pthreads
Presentation transcript:

Outline Unix Architecture Vi Fork Pthread

UNIX Architecture

System Calls and Library Functions Application code C library functions User process System calls kernel

vi

Vi editor have two modes –Command mode –Edit mode start vi : vi [filename] Command mode Edit mode Exit Edit mode Insert Delete Replace Copy..... [Esc]

Edit mode Insert –aInsert word after the cursor –iInsert word after the cursor –oCreate a new line below the cursor –OCreate a new line upon the cursor

Replace and Delete –x delete –ndwdelete n word –ndddelete n line –rreplace a word Undo –Uundo the changes in the same line –uundo the last action Edit –nY or nyycopy n line –P or ppaste –.redo the last action –/search

Command Mode –:wsave –:qexit –:q!exit and no save –:wqsave and exit

Fork

The main purpose is to duplicate the process 。 The new process created by fork is called child process 。 The return value in the child is 0,whereas the return value in the parent is the process ID of the new child 。 It return only -1 when fork failed 。

Pthread

Thread Light weight process Share resources Own private data Synchronization

The Pthread API Three major classes –Thread management –Mutex –Condition valuables All identifiers in the thread library begin with pthread_

Thread Management pthread_create(thread,attr,start_routine,arg)pthread_create pthread_exit (status)pthread_exit pthread_attr_init (attr)pthread_attr_init pthread_attr_destroy (attr)pthread_attr_destroy

Exit Condition The thread returns from its starting routine (the main routine for the initial thread). The thread makes a call to the pthread_exit subroutine. The thread is canceled by another thread via the pthread_cancel routine. The entire process is terminated due to a call to either the exec or exit subroutines.

#include int main() { pid_t pid; pid = fork(); if(pid<0) { printf("fork failed"); exit(1); } else if(pid==0) execlp("/bin/ls","ls","-al",NULL); else { wait(NULL); printf("Child Complete"); exit(0); }

#include #define NUM_THREADS 5 void *PrintHello(void *threadid) { int tid; tid = (int) threadid; printf("Hello World! thread #%d\n", tid); pthread_exit(NULL); } int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc, t; for(t=0;t<NUM_THREADS;t++) { printf("In main: creating thread %d\n", t); rc = pthread_create(&threads[t], NULL, PrintHello,(void *) t); if(rc) { printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); }