Skip to content

Commit

Permalink
Updated with README files per chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
greggagne committed Jul 4, 2014
1 parent bd180db commit b8b01b8
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_STORE
a.out
*.class
2 changes: 2 additions & 0 deletions ch11/README
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Figure 11.2 LockingExample.java

This contains the example Java program showing how file locking is
provided. This example has been modified somewhat from the text in that
the file being locked is passed on the command line.
Expand Down
9 changes: 9 additions & 0 deletions ch12/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The files

file1.txt

and

file2.txt

are associated with exercise 12.21
1 change: 1 addition & 0 deletions ch17/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Figure 17.4 DNSLookUp.java
4 changes: 4 additions & 0 deletions ch2/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This contains the source code and Makefile for the programming
project for creating a Linux kernel module.

Refer to the project for instructions on building the module.
12 changes: 12 additions & 0 deletions ch3/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Figure 3.9 newproc-posix.c
Figure 3.11 newproc-win32.c
Figure 3.17 shm-posix-consumer.c
Figure 3.18 shm-posix-producer.c
Figure 3.21 DateServer.java
Figure 3.22 DateClient.java
Figure 3.25/3.26 unix_pipe.c
Figure 3.27 win32-pipe-parent.c
Figure 3.29 win32-pipe-child.c
Figure 3.30 fork-question-1.c
Figure 3.31 fork-question-2.c
Figure 3.36 simple-shell.c
4 changes: 4 additions & 0 deletions ch4/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Figure 4.9 thrd-posix.c
Figure 4.11 thrd-win32.c
Figure 4.12 Driver.java
OpenMP Example openmp.c
2 changes: 2 additions & 0 deletions ch5/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POSIX unnamed semaphores (Linux) posix-unnamed-sem.c
POSIX named semaphores (OS X) posix-named-sem.c
54 changes: 54 additions & 0 deletions ch5/posix-named-sem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Example illustrating POSIX named semaphores
*
* Compilation (on OS X):
*
* gcc -lpthread posix-named-sem.c
*
* This example includes the appropriate error checking
* that is not covered in the text.
*
* This program illustrates POSIX named semaphores which
* work on OS X systems.
*
* Operating System Concepts - Ninth Edition
* John Wiley & Sons - 2013.
*/

#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <semaphore.h>

int main(void)
{
sem_t *sem;

/**
* Create a named semaphore called 'OSC'
*/

// first remove the semaphore if it already exists
if (sem_unlink("OSC") == -1)
printf("Error removing %s\n",strerror(errno));

// create and initialize the semaphore
if ( (sem = sem_open("OSC", O_CREAT, 0666, 1)) == SEM_FAILED)
printf("Error creating %s\n",strerror(errno));

if (sem_wait(sem) != 0)
printf("Error waiting %s\n",strerror(errno));

printf("*** Critical Section *** \n");

if (sem_post(sem) != 0)
printf("Error posting %s\n",strerror(errno));

printf("*** Non-Critical Section *** \n");

return 0;
}
2 changes: 1 addition & 1 deletion ch5/posix-sem.c → ch5/posix-unnamed-sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Compilation (on Linux):
*
* gcc -lpthread posix-sem.c
* gcc -lpthread posix-unnamed-sem.c
*
* This example includes the appropriate error checking
* that is not covered in the text.
Expand Down
2 changes: 2 additions & 0 deletions ch6/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Figure 6.8 posix-sched.c
Figure 6.20 posix-rt.c
5 changes: 5 additions & 0 deletions ch7/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Figure 7.4 deadlock.c

This program illustrates deadlock - read through it to better understand
how the program operates. Deadlock is not always possible and it depends
upon how the threads are scheduled by the operating system.
98 changes: 98 additions & 0 deletions ch7/deadlock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* A pthread program illustrating deadlock.
*
* Usage:
* gcc deadlock.c -lpthread
* ./a.out
*
* Figure 7.4
*
* @author Gagne, Galvin, Silberschatz
* Operating System Concepts - Ninth Edition
* Copyright John Wiley & Sons - 2013.
*/

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

pthread_mutex_t first_mutex;
pthread_mutex_t second_mutex;

void *do_work_one(void *param);
void *do_work_two(void *param);

int main(int argc, char *argv[])
{
pthread_t tid1, tid2; /* the thread identifiers */
pthread_attr_t attr; /* set of attributes for the thread */

/* get the default attributes */
pthread_attr_init(&attr);

/* create the mutex locks */
pthread_mutex_init(&first_mutex,NULL);
pthread_mutex_init(&second_mutex,NULL);

/* create the threads */
pthread_create(&tid1,&attr,do_work_one,NULL);
pthread_create(&tid2,&attr,do_work_two,NULL);

/* now wait for the thread to exit */
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);

printf("Parent DONE\n");

/* destroy the mutex before exiting */
pthread_mutex_destroy(&first_mutex);
pthread_mutex_destroy(&second_mutex);
}

/**
* The first thread worker
*/
void *do_work_one(void *param)
{
pthread_mutex_lock(&first_mutex);
printf("Worker 1 has acquired first mutex\n");
pthread_mutex_lock(&second_mutex);
printf("Worker 1 has acquired second mutex\n");

/**
* Do some work
*/

printf("Worker 1 is whistling .....\n");

pthread_mutex_unlock(&second_mutex);
pthread_mutex_unlock(&first_mutex);

printf("worker 1 done\n");

pthread_exit(0);
}

/**
* The second thread worker
*/
void *do_work_two(void *param)
{
pthread_mutex_lock(&second_mutex);
printf("Worker 2 has acquired second mutex\n");
pthread_mutex_lock(&first_mutex);
printf("Worker 2 has acquired first mutex\n");

/**
* Do some work
*
*/

printf("Worker 2 is whistling .....\n");

pthread_mutex_unlock(&first_mutex);
pthread_mutex_unlock(&second_mutex);

pthread_exit(0);
}

12 changes: 12 additions & 0 deletions ch9/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The following 3 files are related to virtual memory manager project:

BACKING_STORE.bin
addresses.txt
correct.txt

windows-programs (directory)

README
temp.txt
Figure 9.25 consumer.c
Figure 9.26 producer.c

0 comments on commit b8b01b8

Please sign in to comment.