



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Code examples for programs written in c that demonstrate the use of fork, vfork, and thread functions. The programs are presented in the context of a university course on operating systems and concurrent programming. The first program uses fork to create a child process that runs concurrently with the parent process. The second program uses vfork to create a child process that shares the parent's address space. The third program uses the pthread library to create multiple threads of execution within the same process.
Typology: Lab Reports
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Guilherme
(^) DeSouza@ViGIRTablet
(^) Classes/ece4220_S09/Lectures_Notes/Lecture2.d
Hello World $ (^) ./test_frk_par_child (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello World (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello World (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello World (^) World
Hello (^) World
Hello (^) World
Guilherme
(^) DeSouza@ViGIRTablet
(^) Classes/ece4220_S09/Lectures_Notes/Lecture2.d
Guilherme
(^) DeSouza@ViGIRTablet
(^) Classes/ece4220_S09/Lectures_Notes/Lecture2.d
Hello World $ (^) ./test_thrd (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello World (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello World (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Hello World (^) World
Hello (^) World
Hello (^) World
Hello (^) World
Guilherme
(^) DeSouza@ViGIRTablet
(^) Classes/ece4220_S09/Lectures_Notes/Lecture2.d
Copyright
(^) (C) (^) 2005 ViGIR
(^) Vision-Guided
(^) and (^) Intelligent Robotics
(^) Lab
Written by Guilherme
(^) DeSouza
(^)
http://vigir.ee.uwa.edu.au
This program
(^) is free
(^) software;
(^) you (^) can (^) redistribute it and/or
(^) modify
it under (^) the (^) terms of the
(^) GNU General Public
(^) License
(^) as (^) published by
the (^) Free (^) Software
(^) Foundation, meaning:
keep (^) this (^) copyright
(^) notice,
do not try (^) to (^) make (^) money (^) out of it,
it's (^) distributed
yada (^) yada (^) yada...
#include */ *
(^)
#include
(^)
#include
(^)
static (^) int (^) counter
(^) = 0;
void (^) child( void ) (^) {
printf( "Child (^) initial
(^) count: (^) %d\n" , (^) counter);
counter (^) = 200;
while (^) (1) (^) {
printf( counter++; usleep(1100000); "Child counter
%d\n" , counter);
int (^) main( void ) {
pid_t
pid ;
counter (^) = 100;
printf( "Parent (^) initial count:
(^) %d\n" , (^) counter);
if ((pid = (^) vfork()) <
printf( "vfork error\n"
exit(-1);
(^) }
if (pid (^) == (^) 0) (^) {
// child process
child();
(^) }
while (^) (1) (^) {
printf( counter++; usleep(1000000); "Parent (^) counter
(^) = %d\n"
, (^) counter); }
Copyright
(^) (C) (^) 2005 ViGIR
(^) Vision-Guided
(^) and (^) Intelligent Robotics
(^) Lab
Written by Guilherme
(^) DeSouza
(^)
http://vigir.ee.uwa.edu.au
This program
(^) is free
(^) software;
(^) you (^) can (^) redistribute it and/or
(^) modify
it under (^) the (^) terms of the
(^) GNU General Public
(^) License
(^) as (^) published by
the (^) Free (^) Software
(^) Foundation, meaning:
keep (^) this (^) copyright
(^) notice,
do not try (^) to (^) make (^) money (^) out of (^) it,
it's (^) distributed
yada (^) yada (^) yada...
#include */ *
(^)
#include
(^)
static (^) int (^) counter
(^) = 0;
void (^) My_thread(
(^) void (^) *ptr ) (^) {
printf( "My_thread
(^) initial
(^) count: (^) %d\n" , (^) counter);
counter (^) = 200;
while (^) (1) (^) {
printf( counter++; usleep(1100000); "My_thread:
(^) %d \n" , (^) counter);
pthread_exit(0); }
int (^) main( void ) (^) {
pthread_t
(^) thread1;
pthread_create(
(^) &thread1,
(^) NULL,
(void *)&My_thread, (
void *) counter);
counter (^) = 100;
printf( "ParentThread
(^) initial
(^) count: (^) %d\n" , (^) counter);
while (^) (1) (^) {
printf( counter++; usleep(1000000);
"ParentThread: %d \n"
, (^) counter);