3 * Copyright (C) 2002 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /*****************************************************************************
23 * An example for shared memory use: read data saved in a shared
24 * memory segment from the DirMonitor program
26 * Author: S. Piccardi Jan. 2003
28 * $Id: ReadMonitor.c,v 1.2 2003/01/12 00:24:28 piccardi Exp $
30 *****************************************************************************/
31 #include <sys/types.h>
33 #include <dirent.h> /* directory */
34 #include <stdlib.h> /* C standard library */
40 /* Help printing routine */
43 /* variables for shared memory segment */
56 struct DirProp *shmptr;
59 int main(int argc, char *argv[])
64 * Input section: decode command line parameters
67 opterr = 0; /* don't want writing to stderr */
68 while ( (i = getopt(argc, argv, "hs:l:wrbf")) != -1) {
73 case 'h': /* help option */
74 printf("Wrong -h option use\n");
78 case '?': /* unrecognized options */
79 printf("Unrecognized options -%c\n",optopt);
81 default: /* should not reached */
85 /* ***********************************************************
87 * Options processing completed
91 * ***********************************************************/
92 /* create needed IPC objects */
93 key = ftok("~/gapil/sources/DirMonitor.c", 1); /* define a key */
94 shmid = shmget(key, 4096, 0); /* get a shared memory ID */
96 perror("Cannot find shared memory");
99 if ( (shmptr = shmat(shmid, NULL, 0)) == NULL ) { /* attach to process */
100 perror("Cannot attach segment");
103 if ((mutex = MutexFind(key)) == -1) { /* get the Mutex */
104 perror("Cannot find mutex");
108 MutexLock(mutex); /* lock shared memory */
109 printf("Ci sono %d file dati\n", shmptr->tot_regular);
110 printf("Ci sono %d directory\n", shmptr->tot_dir);
111 printf("Ci sono %d link\n", shmptr->tot_link);
112 printf("Ci sono %d fifo\n", shmptr->tot_fifo);
113 printf("Ci sono %d socket\n", shmptr->tot_sock);
114 printf("Ci sono %d device a caratteri\n", shmptr->tot_char);
115 printf("Ci sono %d device a blocchi\n", shmptr->tot_block);
116 printf("Totale %d file, per %d byte\n",
117 shmptr->tot_files, shmptr->tot_size);
118 MutexUnlock(mutex); /* unlock shared memory */
121 * routine to print usage info and exit
124 printf("Program myls: list file in a directory \n");
126 printf(" myls [-h] dirname \n");
127 printf(" -h print this help\n");