Docsity

Programs Demonstrating Fork, Vfork, and Thread Functions in C - Prof. Guilherme De Souza, Lab Reports of Electrical and Electronics Engineering

Partial preview of the text

Download Programs Demonstrating Fork, Vfork, and Thread Functions in C - Prof. Guilherme De Souza and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

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

WITHOUT

ANY WARRANTY,

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

WITHOUT

ANY WARRANTY,

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);