SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2005 David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 
019 #include <libc.h>
020 #include <stdarg.h>
021 #include <debug.h>
022 
023 static unsigned rien[16384];
024 
025 
026 /**
027  * @file myprog7.c
028  * Tests forks and make sure that private mappings (eg the '.data'
029  * section of the program object file) are really private
030  */
031 
032 
033 static void assign(unsigned * addr, const unsigned val)
034 {
035   bochs_printf("[0x%x]=0x%x <- 0x%x\n", (unsigned)addr, *addr, val);
036   *addr = val;
037   bochs_printf(" ===> 0x%x\n", *addr);
038 }
039 
040 
041 int main()
042 {
043   int i, level;
044   
045   bochs_printf("myprog7: Hello\n");
046 
047   assign(& rien[0], 0x42);
048   assign(& rien[1000], 0x42);
049 
050   level = 0;
051   for (i = 0 ; i < 10 ; i++)
052     {
053       pid_t fork_status;
054 
055       fork_status = fork();
056       if (fork_status == 0)
057         {
058           level ++;
059           bochs_printf("myprog7: I am the child %d %d\n", level, i);
060 
061           assign(& rien[0], 0x0f<<24 | (level << 8) | i);
062           assign(& rien[1000], 0x0a<<24 | (level << 8) | i);
063 
064           if ((i % 2) == 0)
065             {
066               char strprog[20];
067               snprintf(strprog, sizeof(strprog), "myprog%d", i/2 + 1);
068               exec(strprog);
069             } 
070         }
071       else if (fork_status > 0)
072         {
073           bochs_printf("myprog7: I am the father %d %d\n", level, i);
074 
075           assign(& rien[0], 0x8f<<24 | (level << 8) | i);
076           assign(& rien[1000], 0x8a<<24 | (level << 8) | i);
077         }
078       else
079         bochs_printf("myprog7: fork error %d !\n", fork_status);
080     }
081 
082   bochs_printf("myprog7: The end %d %d\n", level, i);
083   assign(& rien[0], 0xff<<24 | (level << 8) | i);
084   assign(& rien[1000], 0xfa<<24 | (level << 8) | i);
085 
086   return 0;
087 }

source navigation ] diff markup ] identifier search ] general search ]