Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/tests/test3.c need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include "syscall.h"
0019 
0020 void
0021 putx (unsigned long l)
0022 {
0023 
0024   int i, li;
0025 
0026   for (i = 7; i >= 0; i--)
0027     if ((li = (l >> (i << 2)) & 0x0F) > 9)
0028       putchar ('A' + li - 0x0A);
0029     else
0030       putchar ('0' + li);
0031 }
0032 
0033 void
0034 print (char *s)
0035 {
0036   while (*s) {
0037     putchar (*s++);
0038   }
0039 }
0040 
0041 void
0042 _start ()
0043 {
0044   int pid;
0045   int info = meminfo ();
0046   unsigned shared_id;
0047   int *shared_mem;
0048 
0049   print ("MEMINFO: ");
0050   putx (info);
0051   print ("\n");
0052 
0053   shared_id = shared_mem_alloc ();
0054   if (shared_id < 0) {
0055     _exit (1);
0056   }
0057   print ("shared_id = ");
0058   putx (shared_id);
0059   print ("\n");
0060 
0061 
0062 
0063   if ((pid = fork ())) {
0064     /* PARENT */
0065     if (waitpid (pid) < 0) {
0066       print ("waitpid returned -1\n");
0067     }
0068 
0069     shared_mem = shared_mem_attach (shared_id);
0070     if ((unsigned) shared_mem == -1) {
0071       shared_mem_free (shared_id);
0072       _exit (1);
0073     }
0074     print ("parent shared_mem = ");
0075     putx ((unsigned) shared_mem);
0076     print ("\n");
0077 
0078     print ("PARENT (");
0079     putx (*shared_mem);
0080     print (")\n");
0081 
0082     shared_mem_detach (shared_mem);
0083     shared_mem_free (shared_id);
0084     _exit (0);
0085 
0086   } else {
0087     /* CHILD */
0088     shared_mem = shared_mem_attach (shared_id);
0089     if ((unsigned) shared_mem == -1) {
0090       shared_mem_free (shared_id);
0091       _exit (1);
0092     }
0093     print ("child shared_mem = ");
0094     putx ((unsigned) shared_mem);
0095     print ("\n");
0096 
0097     *shared_mem = 1;
0098 
0099     shared_mem_detach (shared_mem);
0100 
0101     _exit (0);
0102   }
0103 }
0104 
0105 /* 
0106  * Local Variables:
0107  * indent-tabs-mode: nil
0108  * mode: C
0109  * c-file-style: "gnu"
0110  * c-basic-offset: 2
0111  * End: 
0112  */
0113 
0114 /* vi: set et sw=2 sts=2: */