//------------------------------------------------------------------- // forkfb.cpp // // This program tests page-directory inheritance. // // programmer: ALLAN CRUSE // written on: 29 APR 2003 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), write(), close() #include // for mmap(), munmap() #include // for wait() #define HRES 1280 #define VRES 1024 char filename[] = "/dev/vram"; long *vram = (long*)0x10000000; int main( int argc, char **argv ) { // open the device file int mm = open( filename, O_RDWR ); if ( mm < 0 ) { perror( filename ); exit(1); } int vramsize = lseek( mm, 0, SEEK_END ); int prot = ( PROT_READ | PROT_WRITE ); int flags = MAP_SHARED; vram = (long*)mmap( 0, vramsize, prot, flags, mm, 0 ); printf( "\nMapped %d-MB video frame-buffer ", vramsize >> 20 ); printf( "to user-address %08X \n", vram ); int pid = fork(); if ( pid == 0 ) // child process { int color = 0x00FF00FF; int i; for (i = 0; i < 10*HRES; i++) vram[i] = color; exit(0); } int status; wait( &status ); int color = 0x00777777; int j = 10*HRES; int i; for (i = 0; i < 10*HRES; i++) vram[i+j ] = color; printf( "\nChild process (pid=%d) has terminated\n", pid ); munmap( vram, vramsize ); close( mm ); }