Shared Memory Segments and POSIX Semaphores 1
|
|
|
- Dulcie Harmon
- 10 years ago
- Views:
Transcription
1 Shared Memory Segments and POSIX Semaphores 1 Alex Delis delis -at+ pitt.edu October Acknowledgements to Prof. T. Stamatopoulos, M. Avidor, Prof. A. Deligiannakis, S. Evangelatos, Dr. V. Kanitkar and Dr. K. Tsakalozos. 1/31
2 Mechanisms for IPCs Three (more) types of IPCs: Message Queues (not discussed) Shared Memory Semaphores Each IPC structure is referred to by a non-negative integer identifier. When an IPC is created, the program responsible for this creation provides a key of type key t. The Operating System converts this key into an IPC identifier. 2/31
3 Keys in the IPC Client-Server Paradigm Keys can be created in three ways: 1. The server program creates a new structure by specifying a private key that is IPC PRIVATE. Client has to become explicitly aware of this private key. This is often accomplished with the help of a file generated by the server and then looked-up by the client. 2. Server and client do agree on a key value (often defined and hard-coded in the header). 3. Server and client can agree on a pathname to an existing file in the file system AND a project-id (0..255) and then call ftok() to convert these two values into a unique key! 3/31
4 Keys Keys help identify resources and offer access to the internal structures of the 2 IPC mechanisms (through systems calls): struct shmid ds // for shared segments struct semid ds // for semaphores Wrongly accessing resources returns -1 Access rights for IPC mechanisms: read/write stored in struct ipc perm Included header files: #include <sys/ipc.h> #include <sys/types.h> 4/31
5 The ftok() system call converts a pathname and a project identifier to an IPC-key key t ftok(const char *pathname, int proj id) if ( (thekey=ftok("/tmp/ad.tempfile", 23)) == -1) perror("cannot create key from /tmp/ad. tempfile"); The file /tmp/ad.tempfile must be accessible by the invoking process. 5/31
6 Shared Memory A shared memory region is a portion of physical memory that is shared by multiple processes. memory map of Process A memory map of process B 0 0 0x30000 ox x50000 shared memory 0x70000 region In this region, structures can be set up by processes and others may read/write on them. Synchronization (when it is required) is achieved with the help of semaphores. 6/31
7 Creating a shared segment with shmget() #include <sys/ipc.h> #include <sys/shm.h> int shmget(key t key, size t size, int shmflg) returns the identifier of the shared memory segment associated with the value of the argument key. the returned size of the segment is equal to size rounded up to a multiple of PAGE SIZE. shmflg helps designate the access rights for the segment (IPC CREAT and IPC EXCL are used in a way similar to that of message queues). If shmflg specifies both IPC CREAT and IPC EXCL and a shared memory segment already exists for key, then shmget() fails with errno set to EEXIST. 7/31
8 Attach- and Detach-ing a segment:shmat()/shmdt() void *shmat(int shmid, const void *shmaddr, int shmflg) attaches the shared memory segment identified by shmid to the address space of the calling process. If shmaddr is NULL, the OS chooses a suitable (unused) address at which to attach the segment (frequent choice). Otherwise, shmaddr must be a page-aligned address at which the attach occurs. int shmdt(const void *shmaddr) detaches the shared memory segment located at the address specified by shmaddr from the address space of the calling process. 8/31
9 The system call shmctl() int shmctl(int shmid, int cmd, struct shmid ds *buf) performs the control operation specified by cmd on the shared memory segment whose identifier is given in shmid. The buf argument is a pointer to a shmid ds structure: struct shmid_ds { struct ipc_perm shm_perm; /* Ownership and permissions */ size_t shm_segsz; /* Size of segment ( bytes) */ time_t shm_atime; /* Last attach time */ time_t shm_dtime; /* Last detach time */ time_t shm_ctime; /* Last change time */ pid_t shm_cpid; /* PID of creator */ pid_t shm_lpid; /* PID of last shmat(2)/ shmdt(2) */ shmatt_t shm_nattch; /* No. of current attaches */... }; 9/31
10 The system call shmctl() Usual values for cmd are: IPC STAT: copy information from the kernel data structure associated with shmid into the shmid ds structure pointed to by buf. IPC SET: write the value of some member of the shmid ds structure pointed to by buf to the kernel data structure associated with this shared memory segment, updating also its shm ctime member. IPC RMID: mark the segment to be destroyed. The segment will be destroyed after the last process detaches it (i.e., shm nattch is zero). 10/31
11 Use Cases of Calls Only one process creates the segment: int id; id = shmget(ipc_private, 10, 0666); if ( id == -1 ) perror("creating"); Every (interested) process attaches the segment: int *mem; mem = (int *) shmat (id, (void *)0, 0); if ( (int)mem == -1 ) perror("attachment"); Every process detaches the segment: int err; err = shmdt((void *)mem); if ( err == -1 ) perror("detachment"); Only one process has to remove the segment: int err; err = shmctl(id, IPC_RMID, 0); if ( err == -1 ) perror("removal"); 11/31
12 Creating and accessing shared memory ( sharemem1.c ) # include <stdio.h> # include <sys/types.h> # include <sys/ipc.h> # include <sys/shm.h> int main(int argc, char **argv){ int id=0, err=0; int *mem; id = shmget( IPC_PRIVATE,10,0666); /* Make shared memory segment */ if (id == -1) perror ("Creation"); else printf(" Allocated. %d\n",( int)id); mem = (int *) shmat(id, (void*)0, 0); /* Attach the segment */ if ((int) mem == -1) perror("attachment."); else printf(" Attached. Mem contents %d\n",*mem); *mem=1; /* Give it initial value */ printf(" Start other process. >"); getchar(); printf("mem is now %d\n", *mem); /* Print out new value */ } err = shmctl(id, IPC_RMID, 0); /* Remove segment */ if (err == -1) perror ("Removal."); else printf("removed. %d\n", (int)(err)); return 0; 12/31
13 Creating and accessing shared memory ( sharemem2.c ) # include <stdio.h> # include <stdlib.h> # include <sys/types.h> # include <sys/ipc.h> # include <sys/shm.h> int main(int argc, char **argv) { int id, err; int *mem; if (argc <= 1) { printf("need shared memory id. \n"); exit(1); } sscanf(argv[1], "%d", &id); /* Get id from command line. */ printf("id is %d\n", id); mem = (int *) shmat(id, (void*) 0,0); /* Attach the segment */ if ((int) mem == -1) perror("attachment."); else printf(" Attached. Mem contents %d\n",*mem); *mem=2; /* Give it a different value */ printf(" Changed mem is now %d\n", *mem); } err = shmdt((void *) mem); /* Detach segment */ if (err == -1) perror ("Detachment."); else printf(" Detachment %d\n", err); return 0; 13/31
14 Running the two programs: Starting off with executing sharemem1 : ad@ad-desktop:~/ Set008/src/ SharedSegments$./ sharemem1 Allocated Attached. Mem contents 0 Start other process. > Executing sharemem2 : ad@ad-desktop:~/ Set008/src/ SharedSegments$./ sharemem Id is Attached. Mem contents 1 Changed mem is now 2 Detachment 0 ad@ad-desktop:~/ Set008/src/ SharedSegments$ Providing the final input to sharemem1 : Start other process. >s mem is now 2 Removed. 0 ad@ad-desktop:~/ Set008/src/ SharedSegments$ 14/31
15 Semaphores Fundamental mechanism that facilitates the synchronization of accessing resources placed in shared memory. A semaphore is an integer whose value is never allowed to fall below zero. Two operations can be performed on a semaphore: - increment the semaphore value by one (UP or V() ala Dijkstra). - decrement a semaphore value by one (DOWN or P() ala Dijkstra). If the value of semaphore is currently zero, then the invoking process will block until the value becomes greater than zero. 15/31
16 POSIX Semaphores #include <semaphore.h> sem init, sem destroy, sem post, sem wait, sem trywait int sem init(sem t *sem, int pshared, unsigned int value); The above initializes a semaphore. Compile either with -lrt or -lpthread pshared indicates whether this semaphore is to be shared between the threads of a process, or between processes: zero: semaphore is shared between the threads of a process; should be located at an address visible to all threads. non-zero: semaphore is shared among processes and should be located in a region of shared memory. 16/31
17 POSIX Semaphore Operations sem wait(), sem trywait() int sem wait(sem t *sem); int sem trywait(sem t *sem); Perform P(s) operation. sem wait blocks; sem trywait will fail rather than block. sem post() int sem post(sem t *sem); Perform V(s) operation. sem destroy() int sem destroy(sem t *sem); Destroys a semaphore. 17/31
18 Creating and using a POSIX Semaphore # include <stdio.h> # include <stdlib.h> # include <semaphore.h> # include <sys/types.h> # include <sys/ipc.h> extern int errno; int main(int argc, char **argv) { sem_t sp; int retval; /* Initialize the semaphore. */ retval = sem_init(&sp,1,2); if (retval!= 0) { perror(" Couldn t initialize."); exit(3); } retval = sem_trywait(&sp); printf("did trywait. Returned %d >\n",retval); getchar(); retval = sem_trywait(&sp); printf("did trywait. Returned %d >\n",retval); getchar(); retval = sem_trywait(&sp); printf("did trywait. Returned %d >\n",retval); getchar(); } sem_destroy(& sp); return 0; 18/31
19 Executing the Program Did trywait. Returned 0 > Did trywait. Returned 0 > Did trywait. Returned -1 > ad@ad-desktop:~/src/posixsems$ 19/31
20 Example: semtest3.c /* semtest3.c: POSIX Semaphore test example using shared memory */ # include <stdio.h> # include <stdlib.h> # include <semaphore.h> # include <sys/types.h> # include <sys/ipc.h> # include <sys/shm.h> # define SEGMENTSIZE sizeof(sem_t) # define SEGMENTPERM 0666 int main(int argc, char **argv) { sem_t *sp; int retval; int id, err; /* Make shared memory segment. */ id = shmget( IPC_PRIVATE, SEGMENTSIZE, SEGMENTPERM); if (id == -1) perror("creation"); else printf(" Allocated %d\n", id); /* Attach the segment. */ sp = (sem_t *) shmat(id,(void*) 0, 0); if ((int) sp == -1) { perror("attachment."); exit(2);} 20/31
21 Example: semtest3.c /* Initialize the semaphore. */ retval = sem_init(sp,1,2); if (retval!= 0) { perror(" Couldn t initialize."); exit(3); } retval = sem_trywait(sp); printf("did trywait. Returned %d >\n", retval); getchar(); retval = sem_trywait(sp); printf("did trywait. Returned %d >\n", retval); getchar(); retval = sem_trywait(sp); printf("did trywait. Returned %d >\n", retval); getchar(); sem_destroy(sp); } /* Remove segment. */ err = shmctl(id, IPC_RMID, 0); if (err == -1) perror("removal."); else printf(" Removed. %d\n",err); return 0; 21/31
22 Example: semtest3a.c /* semtest3a.c POSIX Semaphore test example using shared memory */ # include <stdio.h> # include <stdlib.h> # include <semaphore.h> # include <sys/types.h> # include <sys/ipc.h> # include <sys/shm.h> # define SEGMENTSIZE sizeof(sem_t) # define SEGMENTPERM 0666 extern int errno; int main(int argc,char **argv) { sem_t *sp; int retval; int id, err; if (argc <= 1) { printf("need shmem id. \n"); exit(1); } /* Get id from command line. */ sscanf(argv[1], "%d", &id); printf(" Allocated %d\n", id); /* Attach the segment. */ sp = (sem_t *) shmat(id,(void*) 0, 0); if ((int) sp == -1) { perror("attachment."); exit(2);} 22/31
23 Example: semtest3a.c /* Initialize the semaphore. */ retval = sem_init(sp,1,1); if (retval!= 0) { perror(" Couldn t initialize."); exit(3); } retval = sem_trywait(sp); printf("did trywait. Returned %d >\n", retval); getchar(); retval = sem_trywait(sp); printf("did trywait. Returned %d >\n", retval); getchar(); retval = sem_trywait(sp); printf("did trywait. Returned %d >\n", retval); getchar(); } /* Remove segment. */ err = shmdt((void *) sp); if (err == -1) perror ("Detachment."); return 0; 23/31
24 Running the two programs: semtest and semtest3a Starting off with executing semtest : ad@serifos:~/ Recitation4/src$./ semtest3 Allocated Did trywait. Returned 0 > Executing semtest3a in another tty: ad@serifos:~/ Recitation4/src$./ semtest3a Allocated Did trywait. Returned 0 > Did trywait. Returned -1 > Continue with semtest3 : Did trywait. Returned -1 > Did trywait. Returned -1 > 24/31
25 Running the two programs: semtest and semtest3a Continue with semtest3a : Did trywait. Returned -1 > Follow up with semtest3 : Removed. 0 ad@serifos:~/ Recitation4/src$ Finish with semtest3a : ad@serifos:~/ Recitation4/src$ 25/31
26 Initialize and Open a named Semaphore sem t *sem open(const char *name, int oflag); sem t *sem open(const char *name, int oflag, mode t mode, unsigned int value); creates a new POSIX semaphore OR opens an existing semaphore whose name is name. oflag specifies flags that control the operation of the call - O CREAT creates the semaphore; - provided that both O CREAT and O EXCL are specified, an error is returned if a semaphore with name already exists. if oflag is O CREAT then two more arguments have to be used: - mode specifies the permissions to be placed on the new semaphore. - value specifies the initial value for the new semaphore. 26/31
27 More on Named POSIX Semaphores A named semaphore is identified by a (persistent) name that has the form /this is a sample named semaphore. consists of an initial slash followed by a (large) number of character (but no slashes). If you want to see (list) all named sempahores in your (Linux) system look at directory /dev/shm int sem close(sem t *sem) closes the named semaphore referred to by sem freeing the system resources the invoking process has used. int sem unlink(const char *name) removes the named semaphore in question. int sem getvalue(sem t *sem, int *sval) obtains the current value of semaphore.. the cheater API-call! 27/31
28 Named POSIX Semaphore # include <stdio.h>... # include <sys/stat.h> # include <semaphore.h> int main(int argc, char *argv[]){ const char * semname; int op=0; int val=0; if (argc ==3) { semname=argv[1]; op=atoi(argv[2]); } else { printf(" usage: namesem nameofsem Operation\n"); exit(1); } sem_t *sem=sem_open(semname, O_CREAT O_EXCL, S_IRUSR S_IWUSR, 0); if (sem!= SEM_FAILED) printf(" created new semaphore!\n"); else if (errno== EEXIST ) { printf(" semaphore appears to exist already!\n"); sem = sem_open(semname, 0); } else ; assert(sem!= SEM_FAILED); sem_getvalue(sem, & val); printf(" semaphore s before action value is %d\n",val); 28/31
29 Named Posix Semaphore if ( op == 1 ) { printf(" incrementing semaphore\n"); sem_post(sem); } else if ( op == -1 ) { printf(" decrementing semaphore\n"); sem_wait(sem); } else if ( op == 2 ){ printf(" clearing up named semaphore\n"); sem_close(sem); // close the sem sem_unlink(semname); // remove it from system exit(1); } else printf("not defined operation! \n"); sem_getvalue(sem, & val); printf(" semaphore s current value is %d\n",val); sem_close(sem); return(0); } 29/31
30 Execution Outcome PosixSems$ ls /dev/shm/ pulse-shm pulse-shm pulse-shm pulse-shm pulse-shm pulse-shm PosixSems$./ namedsem / delis 1 created new semaphore! semaphore s before action value is 0 incrementing semaphore semaphore s current value is 1 ad@serifos:~/ PosixSems$ ls /dev/shm/ pulse-shm pulse-shm pulse-shm sem. delis pulse-shm pulse-shm pulse-shm ad@serifos:~/ PosixSems$./ namedsem / delis -1 semaphore appears to exist already! semaphore s before action value is 1 decrementing semaphore semaphore s current value is 0 ad@serifos:~/ PosixSems$./ namedsem / delis 2 semaphore appears to exist already! semaphore s before action value is 0 clearing up named semaphore ad@serifos:~/ PosixSems$ ls /dev/shm/ pulse-shm pulse-shm pulse-shm pulse-shm pulse-shm pulse-shm ad@serifos:~/ PosixSems$./ namedsem / delis 1 created new semaphore! semaphore s before action value is 0 incrementing semaphore semaphore s current value is 1 30/31
31 Execution Outcome PosixSems$./ namedsem / delis 1 semaphore appears to exist already! semaphore s before action value is 1 incrementing semaphore semaphore s current value is 2 ad@serifos:~/ PosixSems$ ls /dev/shm/ pulse-shm pulse-shm pulse-shm sem. delis pulse-shm pulse-shm pulse-shm ad@serifos:~/ PosixSems$./ namedsem / delis -1 semaphore appears to exist already! semaphore s before action value is 2 decrementing semaphore semaphore s current value is 1 ad@serifos:~/ PosixSems$./ namedsem / delis -1 semaphore appears to exist already! semaphore s before action value is 1 decrementing semaphore semaphore s current value is 0 ad@serifos:~/ PosixSems$./ namedsem / delis 2 semaphore appears to exist already! semaphore s before action value is 0 clearing up named semaphore ad@serifos:~/ PosixSems$ ls /dev/shm/ pulse-shm pulse-shm pulse-shm pulse-shm pulse-shm pulse-shm ad@serifos:~/ PosixSems$ 31/31
IPC. Semaphores were chosen for synchronisation (out of several options).
IPC Two processes will use shared memory to communicate and some mechanism for synchronise their actions. This is necessary because shared memory does not come with any synchronisation tools: if you can
Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c 2015. February 2015
Linux/UNIX System Programming POSIX Shared Memory Michael Kerrisk, man7.org c 2015 February 2015 Outline 22 POSIX Shared Memory 22-1 22.1 Overview 22-3 22.2 Creating and opening shared memory objects 22-10
Unix System Calls. Dept. CSIE 2006.12.25
Unix System Calls Gwan-Hwan Hwang Dept. CSIE National Taiwan Normal University 2006.12.25 UNIX System Overview UNIX Architecture Login Name Shells Files and Directories File System Filename Pathname Working
System Calls Related to File Manipulation
KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 12 System Calls Related to File Manipulation Objective: In this lab we will be
Shared Memory Introduction
12 Shared Memory Introduction 12.1 Introduction Shared memory is the fastest form of IPC available. Once the memory is mapped into the address space of the processes that are sharing the memory region,
CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17
CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17 System Calls for Processes Ref: Process: Chapter 5 of [HGS]. A program in execution. Several processes are executed concurrently by the
Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes
Computer Systems II Creating and Executing Processes 1 Unix system calls fork( ) wait( ) exit( ) 2 How To Create New Processes? Underlying mechanism - A process runs fork to create a child process - Parent
OS: IPC I. Cooperating Processes. CIT 595 Spring 2010. Message Passing vs. Shared Memory. Message Passing: Unix Pipes
Cooperating Processes Independent processes cannot affect or be affected by the execution of another process OS: IPC I CIT 595 Spring 2010 Cooperating process can affect or be affected by the execution
System Calls and Standard I/O
System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services
Operating Systems and Networks
recap Operating Systems and Networks How OS manages multiple tasks Virtual memory Brief Linux demo Lecture 04: Introduction to OS-part 3 Behzad Bordbar 47 48 Contents Dual mode API to wrap system calls
Operating System Structure
Operating System Structure Lecture 3 Disclaimer: some slides are adopted from the book authors slides with permission Recap Computer architecture CPU, memory, disk, I/O devices Memory hierarchy Architectural
LOW LEVEL FILE PROCESSING
LOW LEVEL FILE PROCESSING 1. Overview The learning objectives of this lab session are: To understand the functions provided for file processing by the lower level of the file management system, i.e. the
Lecture 24 Systems Programming in C
Lecture 24 Systems Programming in C A process is a currently executing instance of a program. All programs by default execute in the user mode. A C program can invoke UNIX system calls directly. A system
Programmation Systèmes Cours 7 IPC: FIFO
Programmation Systèmes Cours 7 IPC: FIFO Stefano Zacchiroli [email protected] Laboratoire PPS, Université Paris Diderot - Paris 7 15 novembre 2011 URL http://upsilon.cc/zack/teaching/1112/progsyst/ Copyright
Introduction. dnotify
Introduction In a multi-user, multi-process operating system, files are continually being created, modified and deleted, often by apparently unrelated processes. This means that any software that needs
Lecture 17. Process Management. Process Management. Process Management. Inter-Process Communication. Inter-Process Communication
Process Management Lecture 17 Review February 25, 2005 Program? Process? Thread? Disadvantages, advantages of threads? How do you identify processes? How do you fork a child process, the child process
Shared Address Space Computing: Programming
Shared Address Space Computing: Programming Alistair Rendell See Chapter 6 or Lin and Synder, Chapter 7 of Grama, Gupta, Karypis and Kumar, and Chapter 8 of Wilkinson and Allen Fork/Join Programming Model
Critical section problem (repetition)
C&UNIX Critical section problem (repetition) 1 Critical section problem (repetition) repeat entry section critical section exit section remainder section until false; Två processer: P 0, P 1 ej samtidigt
Process definition Concurrency Process status Process attributes PROCESES 1.3
Process Management Outline Main concepts Basic services for process management (Linux based) Inter process communications: Linux Signals and synchronization Internal process management Basic data structures:
How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes
Content Introduction and History File I/O The File System Shell Programming Standard Unix Files and Configuration Processes Programs are instruction sets stored on a permanent medium (e.g. harddisc). Processes
Linux Driver Devices. Why, When, Which, How?
Bertrand Mermet Sylvain Ract Linux Driver Devices. Why, When, Which, How? Since its creation in the early 1990 s Linux has been installed on millions of computers or embedded systems. These systems may
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG
Channel Access Client Programming Andrew Johnson Computer Scientist, AES-SSG Channel Access The main programming interface for writing Channel Access clients is the library that comes with EPICS base Written
1 Posix API vs Windows API
1 Posix API vs Windows API 1.1 File I/O Using the Posix API, to open a file, you use open(filename, flags, more optional flags). If the O CREAT flag is passed, the file will be created if it doesnt exist.
Introduction to UNIX System Programming
Introduction to UNIX System Programming Page number : Chapter 1 : Introduction 3 1.1. Man command.. 3 1.2. System Calls and Library calls 4 1.3. Using system calls and library functions.. 5 1.4. Error
Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture
Last Class: OS and Computer Architecture System bus Network card CPU, memory, I/O devices, network card, system bus Lecture 3, page 1 Last Class: OS and Computer Architecture OS Service Protection Interrupts
Debugging with TotalView
Tim Cramer 17.03.2015 IT Center der RWTH Aachen University Why to use a Debugger? If your program goes haywire, you may... ( wand (... buy a magic... read the source code again and again and...... enrich
Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights
Outline Review Inter process communication Signals Fork Pipes FIFO Spotlights 1 6.087 Lecture 14 January 29, 2010 Review Inter process communication Signals Fork Pipes FIFO Spotlights 2 Review: multithreading
RTAI API Inter Process Communication
RTAI API Inter Process Communication Antonio Barbalace [email protected] Overview Semaphores Shared Memory FIFOs Mailbox Typed Mailbox Messages POSIX Message Queue Antonio Barbalace 2009 RTOS
NDK: NOVELL NSS AUDIT
www.novell.com/documentation NDK: NOVELL NSS AUDIT Developer Kit August 2015 Legal Notices Novell, Inc., makes no representations or warranties with respect to the contents or use of this documentation,
Operating Systems. Privileged Instructions
Operating Systems Operating systems manage processes and resources Processes are executing instances of programs may be the same or different programs process 1 code data process 2 code data process 3
ARUNNING INSTANCE OF A PROGRAM IS CALLED A PROCESS. If you have two
3 Processes ARUNNING INSTANCE OF A PROGRAM IS CALLED A PROCESS. If you have two terminal windows showing on your screen, then you are probably running the same terminal program twice you have two terminal
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
REAL TIME SYSTEMS. Piotr MALECKI
SHARED MEMORY and MEMORY MAPPED FILES ALLOW PROCESSES TO COMMUNICATE PROCESSES SHARE PORTIONS OF THEIR ADDRESS SPACE WHEN ONE WRITES, THA DATA IS IMMEDIATELY AVAILABLE TO OTHERS COMMUNICATION IS FAST NO
Parallelization: Binary Tree Traversal
By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First
5. Processes and Memory Management
5. Processes and Memory Management 5. Processes and Memory Management Process Abstraction Introduction to Memory Management Process Implementation States and Scheduling Programmer Interface Process Genealogy
Threads Scheduling on Linux Operating Systems
Threads Scheduling on Linux Operating Systems Igli Tafa 1, Stavri Thomollari 2, Julian Fejzaj 3 Polytechnic University of Tirana, Faculty of Information Technology 1,2 University of Tirana, Faculty of
Writing a C-based Client/Server
Working the Socket Writing a C-based Client/Server Consider for a moment having the massive power of different computers all simultaneously trying to compute a problem for you -- and still being legal!
Networks and Protocols Course: 320301 International University Bremen Date: 2004-11-24 Dr. Jürgen Schönwälder Deadline: 2004-12-03.
Networks and Protocols Course: 320301 International University Bremen Date: 2004-11-24 Dr. Jürgen Schönwälder Deadline: 2004-12-03 Problem Sheet #10 Problem 10.1: finger rpc server and client implementation
Systemnahe Programmierung KU
S C I E N C E P A S S I O N T E C H N O L O G Y Systemnahe Programmierung KU A6,A7 www.iaik.tugraz.at 1. Virtual Memory 2. A7 - Fast-Food Restaurant 2 Course Overview A8, A9 System Programming A7 Thread
/* File: blkcopy.c. size_t n
13.1. BLOCK INPUT/OUTPUT 505 /* File: blkcopy.c The program uses block I/O to copy a file. */ #include main() { signed char buf[100] const void *ptr = (void *) buf FILE *input, *output size_t
Linux Kernel Rootkit : Virtual Terminal Key Logger
Linux Kernel Rootkit : Virtual Terminal Key Logger Jeena Kleenankandy Roll No. P140066CS Depatment of Computer Science and Engineering National Institute of Technology Calicut jeena [email protected]
CSE 333 SECTION 6. Networking and sockets
CSE 333 SECTION 6 Networking and sockets Goals for Today Overview of IP addresses Look at the IP address structures in C/C++ Overview of DNS Write your own (short!) program to do the domain name IP address
Green Telnet. Making the Client/Server Model Green
Green Telnet Reducing energy consumption is of growing importance. Jeremy and Ken create a "green telnet" that lets clients transition to a low-power, sleep state. By Jeremy Blackburn and Ken Christensen,
ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters
The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters
Priority Based Implementation in Pintos
Priority Based Implementation in Pintos Deepa D 1, Nivas K S 2, Preethi V 3 1, 2, 3 Students M-Tech, Dept. of Information Technology, SNS College of Engg., Coimbatore. Abstract Pintos is a simple operating
Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions
Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment
Testing Database Performance with HelperCore on Multi-Core Processors
Project Report on Testing Database Performance with HelperCore on Multi-Core Processors Submitted by Mayuresh P. Kunjir M.E. (CSA) Mahesh R. Bale M.E. (CSA) Under Guidance of Dr. T. Matthew Jacob Problem
File Handling. What is a file?
File Handling 1 What is a file? A named collection of data, stored in secondary storage (typically). Typical operations on files: Open Read Write Close How is a file stored? Stored as sequence of bytes,
Introduction to Socket programming using C
Introduction to Socket programming using C Goal: learn how to build client/server application that communicate using sockets Vinay Narasimhamurthy [email protected] CLIENT SERVER MODEL Sockets are
IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.
Aim: IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking. Other Objective of this lab session is to learn how to do socket
Migration of Process Credentials
C H A P T E R - 5 Migration of Process Credentials 5.1 Introduction 5.2 The Process Identifier 5.3 The Mechanism 5.4 Concluding Remarks 100 CHAPTER 5 Migration of Process Credentials 5.1 Introduction Every
Setting up PostgreSQL
Setting up PostgreSQL 1 Introduction to PostgreSQL PostgreSQL is an object-relational database management system based on POSTGRES, which was developed at the University of California at Berkeley. PostgreSQL
Lecture 25 Systems Programming Process Control
Lecture 25 Systems Programming Process Control A process is defined as an instance of a program that is currently running. A uni processor system or single core system can still execute multiple processes
About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer
About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.
Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY. 6.828 Operating System Engineering: Fall 2005
Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.828 Operating System Engineering: Fall 2005 Quiz II Solutions Average 84, median 83, standard deviation
1 Abstract Data Types Information Hiding
1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content
Data Types in the Kernel
,ch11.3440 Page 288 Thursday, January 20, 2005 9:25 AM CHAPTER 11 Data Types in the Kernel Chapter 11 Before we go on to more advanced topics, we need to stop for a quick note on portability issues. Modern
Programmation Systèmes Cours 9 Memory Mapping
Programmation Systèmes Cours 9 Memory Mapping Stefano Zacchiroli [email protected] Laboratoire PPS, Université Paris Diderot - Paris 7 24 novembre 2011 URL http://upsilon.cc/zack/teaching/1112/progsyst/
W4118 Operating Systems. Junfeng Yang
W4118 Operating Systems Junfeng Yang Outline Linux overview Interrupt in Linux System call in Linux What is Linux A modern, open-source OS, based on UNIX standards 1991, 0.1 MLOC, single developer Linus
Sistemi Operativi. Lezione 25: JOS processes (ENVS) Corso: Sistemi Operativi Danilo Bruschi A.A. 2015/2016
Sistemi Operativi Lezione 25: JOS processes (ENVS) 1 JOS PCB (ENV) 2 env_status ENV_FREE: Indicates that the Env structure is inactive, and therefore on the env_free_list. ENV_RUNNABLE: Indicates that
Leak Check Version 2.1 for Linux TM
Leak Check Version 2.1 for Linux TM User s Guide Including Leak Analyzer For x86 Servers Document Number DLC20-L-021-1 Copyright 2003-2009 Dynamic Memory Solutions LLC www.dynamic-memory.com Notices Information
INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens
INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens Read: Chapters 1,2, 3, 4 Communications Client Example: Ex: TCP/IP Server Telnet client on local machine to Telnet server on
Implementing Network Software
Implementing Network Software Outline Sockets Example Process Models Message Buffers Spring 2007 CSE 30264 1 Sockets Application Programming Interface (API) Socket interface socket : point where an application
REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux
REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux Lesson-12: Real Time Linux 1 1. Real Time Linux 2 Linux 2.6.x Linux is after Linus Torvalds, father of the Linux operating
Minix Mini Unix (Minix) basically, a UNIX - compatible operating system. Minix is small in size, with microkernel-based design. Minix has been kept
Minix Mini Unix (Minix) basically, a UNIX - compatible operating system. Minix is small in size, with microkernel-based design. Minix has been kept (relatively) small and simple. Minix is small, it is
Tutorial on Socket Programming
Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Seyed Hossein Mortazavi (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian, ) 1 Outline Client- server
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive
NS3 Lab 1 TCP/IP Network Programming in C
NS3 Lab 1 TCP/IP Network Programming in C Dr Colin Perkins School of Computing Science University of Glasgow http://csperkins.org/teaching/ns3/ 13/14 January 2015 Introduction The laboratory exercises
Tutorial on C Language Programming
Tutorial on C Language Programming Teodor Rus [email protected] The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:
FAME Operating Systems
FAME Operating Systems 2012 David Picard contributors : Arnaud Revel, Mickaël Maillard [email protected] 1. Introduction A very simple computer Goals of an operating system Hardware management Task management
The Plan Today... System Calls and API's Basics of OS design Virtual Machines
System Calls + The Plan Today... System Calls and API's Basics of OS design Virtual Machines System Calls System programs interact with the OS (and ultimately hardware) through system calls. Called when
iphone Objective-C Exercises
iphone Objective-C Exercises About These Exercises The only prerequisite for these exercises is an eagerness to learn. While it helps to have a background in object-oriented programming, that is not a
Parallel Computing. Shared memory parallel programming with OpenMP
Parallel Computing Shared memory parallel programming with OpenMP Thorsten Grahs, 27.04.2015 Table of contents Introduction Directives Scope of data Synchronization 27.04.2015 Thorsten Grahs Parallel Computing
How to Add a New System Call for Minix 3
How to Add a New System Call for Minix 3 Karthick Jayaraman Department of Electrical Engineering & Computer Science Syracuse University, Syracuse, New York 1. Introduction Minix3 has the micro-kernel architecture.
Programming the Cell Multiprocessor: A Brief Introduction
Programming the Cell Multiprocessor: A Brief Introduction David McCaughan, HPC Analyst SHARCNET, University of Guelph [email protected] Overview Programming for the Cell is non-trivial many issues to be
OPERATING SYSTEM SERVICES
OPERATING SYSTEM SERVICES USER INTERFACE Command line interface(cli):uses text commands and a method for entering them Batch interface(bi):commands and directives to control those commands are entered
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
Jorix kernel: real-time scheduling
Jorix kernel: real-time scheduling Joris Huizer Kwie Min Wong May 16, 2007 1 Introduction As a specialized part of the kernel, we implemented two real-time scheduling algorithms: RM (rate monotonic) and
The POSIX Socket API
The POSIX Giovanni Agosta Piattaforme Software per la Rete Modulo 2 G. Agosta The POSIX Outline Sockets & TCP Connections 1 Sockets & TCP Connections 2 3 4 G. Agosta The POSIX TCP Connections Preliminaries
ADVANCED MAC OS X ROOTKITS
ADVANCED MAC OS X ROOTKITS DINO A. DAI ZOVI [email protected] Abstract. The Mac OS X kernel (xnu) is a hybrid BSD and Mach kernel. While Unix-oriented rootkit techniques are pretty well known, Mach-based
Comp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
64-Bit NASM Notes. Invoking 64-Bit NASM
64-Bit NASM Notes The transition from 32- to 64-bit architectures is no joke, as anyone who has wrestled with 32/64 bit incompatibilities will attest We note here some key differences between 32- and 64-bit
Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11
Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11 In this lab, you will first learn how to use pointers to print memory addresses of variables. After that, you will learn
Intro to GPU computing. Spring 2015 Mark Silberstein, 048661, Technion 1
Intro to GPU computing Spring 2015 Mark Silberstein, 048661, Technion 1 Serial vs. parallel program One instruction at a time Multiple instructions in parallel Spring 2015 Mark Silberstein, 048661, Technion
CUDA Debugging. GPGPU Workshop, August 2012. Sandra Wienke Center for Computing and Communication, RWTH Aachen University
CUDA Debugging GPGPU Workshop, August 2012 Sandra Wienke Center for Computing and Communication, RWTH Aachen University Nikolay Piskun, Chris Gottbrath Rogue Wave Software Rechen- und Kommunikationszentrum
Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine
7 Objectives After completing this lab you will: know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine Introduction Branches and jumps provide ways to change
Lecture 22: C Programming 4 Embedded Systems
Lecture 22: C Programming 4 Embedded Systems Today s Goals Basic C programming process Variables and constants in C Pointers to access addresses Using a High Level Language High-level languages More human
Module 816. File Management in C. M. Campbell 1993 Deakin University
M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working
SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)
SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics
MatrixSSL Developer s Guide
MatrixSSL Developer s Guide This document discusses developing with MatrixSSL. It includes instructions on integrating MatrixSSL into an application and a description of the configurable options for modifying
Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur
Socket Programming Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur Background Demultiplexing Convert host-to-host packet delivery service into a process-to-process communication channel
CSC230 Getting Starting in C. Tyler Bletsch
CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly
Computer Science & Engineering
DCE GURGAON LAB MANUAL Computer Science & Engineering OPERATING SYSTEM CHAIN SINGH ASSISTANT PROFESSOR CSE DEPARTMENT Operating System Lab MTCE-610A List of Experiments 1. Write programs using the following
Chapter 12 File Management
Operating Systems: Internals and Design Principles, 6/E William Stallings Chapter 12 File Management Dave Bremer Otago Polytechnic, N.Z. 2008, Prentice Hall Roadmap Overview File organisation and Access
Chapter 12 File Management. Roadmap
Operating Systems: Internals and Design Principles, 6/E William Stallings Chapter 12 File Management Dave Bremer Otago Polytechnic, N.Z. 2008, Prentice Hall Overview Roadmap File organisation and Access
64 Bit File Access. 1.0 Introduction. 2.0 New Interfaces. 2.1 New User Visible Types. Adam Sweeney
64 Bit File Access Adam Sweeney 1.0 Introduction In order to support the access of 64 bit files from 32 bit applications, new interfaces must be defined which take 64 bit parameters. These interfaces must
Project No. 2: Process Scheduling in Linux Submission due: April 28, 2014, 11:59pm
Project No. 2: Process Scheduling in Linux Submission due: April 28, 2014, 11:59pm PURPOSE Getting familiar with the Linux kernel source code. Understanding process scheduling and how different parameters
