Linux Processes & Threads

Slides:



Advertisements
Similar presentations
CSE 451: Operating Systems Winter 2009 Module 4 Processes Mark Zbikowski Gary Kimura.
Advertisements

Introduction to Kernel
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.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix Threads operating systems. User Thread Packages pthread package mach c-threads Sun Solaris3 UI threads Kernel Threads Windows NT, XP operating systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
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 in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
Thread Synchronization with Semaphores
10/16/ Realizing Concurrency using the thread model B. Ramamurthy.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
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.
Today’s topic Pthread Some materials and figures are obtained from the POSIX threads Programming tutorial at
B. RAMAMURTHY 10/24/ Realizing Concurrency using the thread model.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Threads and Thread Control Thread Concepts Pthread Creation and Termination Pthread synchronization Threads and Signals.
CE Operating Systems Lecture 10 Processes and process management in Linux.
System calls for Process management
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Threads CSCE Thread Motivation Processes are expensive to create. Context switch between processes is expensive Communication between processes.
S -1 Posix Threads. S -2 Thread Concepts Threads are "lightweight processes" –10 to 100 times faster than fork() Threads share: –process instructions,
Threads and Locking Ioctl operations. Threads Lightweight processes What’s wrong with processes? –fork() is expensive – 10 to 100 times slower –Inter.
Threads Chapter 26. Threads Light-weight processes Each process can have multiple threads of concurrent control. What’s wrong with processes? fork() is.
Operating Systems Process Creation
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
Threads A thread is an alternative model of program execution
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
System calls for Process management Process creation, termination, waiting.
Thread Basic Thread operations include thread creation, termination, synchronization, data management Threads in the same process share:  Process address.
B. RAMAMURTHY 5/10/2013 Amrita-UB-MSES Realizing Concurrency using the thread model.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
Tutorial 4. In this tutorial session we’ll see Threads.
A thread is a basic unit of CPU utilization within a process Each thread has its own – thread ID – program counter – register set – stack It shares the.
Realizing Concurrency using the thread model
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Introduction to Kernel
Realizing Concurrency using the thread model
Threads Threads.
Boost String API & Threads
Thread Programming.
Chapter 4: Threads.
Using Processes.
Unix Process Management
Processes in Unix, Linux, and Windows
Realizing Concurrency using Posix Threads (pthreads)
Operating Systems Lecture 13.
Realizing Concurrency using the thread model
Processes in Unix, Linux, and Windows
System Structure and Process Model
Thread Programming.
Realizing Concurrency using the thread model
Lab 5 Process Control Operating System Lab.
Tutorial 3 Tutorial 3.
CSE 451: Operating Systems Winter 2010 Module 4 Processes
Operating System Concepts
Jonathan Walpole Computer Science Portland State University
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Realizing Concurrency using the thread model
Programming with Shared Memory
Realizing Concurrency using Posix Threads (pthreads)
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
Tutorial 4.
Presentation transcript:

Linux Processes & Threads Jim Fawcett CSE775 – Distributed Objects Spring 2012 Linux Processes & Threads

References Advanced Programming in the Unix Environment, Stevens & Rago, Addison Wesley, Second Edition, 2005 The Linux Programming Interface, Kerrisk, no starch press, 2010 Programming with POSIX Threads, Butenhof, Addison Wesley, 1997

Linux Processes A Linux process is a kernel entity to which system resources are allocated to execute a program. A Process consists of: User-space memory containing a program’s code and variables and kernel data structures that hold information about the process This includes ids associated with the process, virtual memory tables, table of open file descriptors, signal handling information, process resource state and limits, current working directory, …

Process Structure Text segment (sharable, read only) Machine language program instructions Initialized data segment Global and local static data that are initialized, read when the program is loaded Uninitialized data segment (not stored on disk) Uninitialized global and static data, filled with zeros when loaded Stack Dynamically allocated stack frames for each program scope. Heap Area for dynamic memory allocations made by program.

Creating a Child Process There are two primary ways to create a child process: Call fork() which creates a clone of the parent process. Usually there is distinct code for parent and for child. See the Fork example. Call one of the exec() functions. These fork() but then purge the process of the parent code and data and load another program for execution. See Execl example.

Linux Threads A Linux thread has: A process unique thread id A set of register values A stack A scheduling priority and policy A signal mask An errno value Thread specific data

Linux Threads Headers Create Thread #include <pthread.h> Int pthread_Create( pthread_t* restrict pTid, const pthread_attr_t* restrict pAttr, void* (*pRunfunc)(void*), void* restrict pArg ); Returns 0 if OK, error number on failure

Thread Creation Thread starts running function pointed to by pRunfunc with single argument *pArg This, of course, could be a struct of arguments pTid points to thread id supplied by create pAttr points to thread attributes structure Null implies default attributes Terminates when *pRunfunc completes. No guarantees whether creator or thread run first.

Thread Creation Linux creates a “thread” by cloning the parent thread’s process. That clone shares part of the parent’s execution context like memory and file descriptors. Each thread has its own stack. Two threads can share global data and anything passed to both in arg structures.

Thread Termination There are three ways a thread can terminate without ending its parent process: Return from *pRunfunc. Return value is thread’s exit code. Thread can be canceled by another thread in same process: Int pthread_cancel(pthread_t tid); Call pthread_exit(void* returnValue)

Wait for Thread to Complete One thread, usually the parent, can wait for termination of a thread by calling: int pthread_join(pthread_t tid, void** returnVal); The return value is 0 on success, otherwise a failure code.

That’s All Folks