From b8b01b89f1657e72ea331ead9cb13f91047e9d21 Mon Sep 17 00:00:00 2001 From: Greg Gagne Date: Thu, 3 Jul 2014 18:28:26 -0600 Subject: [PATCH] Updated with README files per chapter --- .gitignore | 2 + ch11/README | 2 + ch12/README | 9 +++ ch17/README | 1 + ch2/README | 4 + ch3/README | 12 +++ ch4/README | 4 + ch5/README | 2 + ch5/posix-named-sem.c | 54 +++++++++++++ ch5/{posix-sem.c => posix-unnamed-sem.c} | 2 +- ch6/README | 2 + ch7/README | 5 ++ ch7/deadlock.c | 98 ++++++++++++++++++++++++ ch9/README | 12 +++ 14 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 ch12/README create mode 100644 ch17/README create mode 100644 ch2/README create mode 100644 ch3/README create mode 100644 ch4/README create mode 100644 ch5/README create mode 100644 ch5/posix-named-sem.c rename ch5/{posix-sem.c => posix-unnamed-sem.c} (96%) create mode 100644 ch6/README create mode 100644 ch7/README create mode 100755 ch7/deadlock.c create mode 100644 ch9/README diff --git a/.gitignore b/.gitignore index fd5106f..3caf8bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .DS_STORE +a.out +*.class diff --git a/ch11/README b/ch11/README index 191d21d..89ceb5a 100755 --- a/ch11/README +++ b/ch11/README @@ -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. diff --git a/ch12/README b/ch12/README new file mode 100644 index 0000000..912e76b --- /dev/null +++ b/ch12/README @@ -0,0 +1,9 @@ +The files + + file1.txt + +and + + file2.txt + +are associated with exercise 12.21 diff --git a/ch17/README b/ch17/README new file mode 100644 index 0000000..b4808be --- /dev/null +++ b/ch17/README @@ -0,0 +1 @@ +Figure 17.4 DNSLookUp.java diff --git a/ch2/README b/ch2/README new file mode 100644 index 0000000..f6f290f --- /dev/null +++ b/ch2/README @@ -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. diff --git a/ch3/README b/ch3/README new file mode 100644 index 0000000..d15c417 --- /dev/null +++ b/ch3/README @@ -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 diff --git a/ch4/README b/ch4/README new file mode 100644 index 0000000..a11162f --- /dev/null +++ b/ch4/README @@ -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 diff --git a/ch5/README b/ch5/README new file mode 100644 index 0000000..07121a4 --- /dev/null +++ b/ch5/README @@ -0,0 +1,2 @@ +POSIX unnamed semaphores (Linux) posix-unnamed-sem.c +POSIX named semaphores (OS X) posix-named-sem.c diff --git a/ch5/posix-named-sem.c b/ch5/posix-named-sem.c new file mode 100644 index 0000000..00d9f43 --- /dev/null +++ b/ch5/posix-named-sem.c @@ -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 +#include +#include +#include +#include +#include +#include +#include + +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; +} diff --git a/ch5/posix-sem.c b/ch5/posix-unnamed-sem.c similarity index 96% rename from ch5/posix-sem.c rename to ch5/posix-unnamed-sem.c index bfc392b..bdcc1ca 100644 --- a/ch5/posix-sem.c +++ b/ch5/posix-unnamed-sem.c @@ -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. diff --git a/ch6/README b/ch6/README new file mode 100644 index 0000000..50cd961 --- /dev/null +++ b/ch6/README @@ -0,0 +1,2 @@ +Figure 6.8 posix-sched.c +Figure 6.20 posix-rt.c diff --git a/ch7/README b/ch7/README new file mode 100644 index 0000000..43b025d --- /dev/null +++ b/ch7/README @@ -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. diff --git a/ch7/deadlock.c b/ch7/deadlock.c new file mode 100755 index 0000000..ae415dd --- /dev/null +++ b/ch7/deadlock.c @@ -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 +#include +#include + +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); +} + diff --git a/ch9/README b/ch9/README new file mode 100644 index 0000000..f8e42ff --- /dev/null +++ b/ch9/README @@ -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