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 *****************************************************************************/
29 #include <sys/types.h> /* primitive system data types */
30 #include <sys/stat.h> /* file characteristics constants and functions */
31 #include <dirent.h> /* directory operation constants and functions */
32 #include <stdlib.h> /* C standard library */
33 #include <unistd.h> /* unix standard library */
38 /* Help printing routine */
41 /* variables for shared memory segment */
54 struct DirProp *shmptr;
57 int main(int argc, char *argv[])
62 * Input section: decode command line parameters
65 opterr = 0; /* don't want writing to stderr */
66 while ( (i = getopt(argc, argv, "hs:l:wrbf")) != -1) {
71 case 'h': /* help option */
72 printf("Wrong -h option use\n");
76 case '?': /* unrecognized options */
77 printf("Unrecognized options -%c\n",optopt);
79 default: /* should not reached */
83 /* ***********************************************************
85 * Options processing completed
89 * ***********************************************************/
90 /* create needed IPC objects */
91 key = ftok("~/gapil/sources/DirMonitor.c", 1); /* define a key */
92 if (!(shmptr = ShmFind(key, 4096))) { /* get a shared memory segment */
93 perror("Cannot find shared memory");
96 if ((mutex = MutexFind(key)) == -1) { /* get the Mutex */
97 perror("Cannot find mutex");
100 MutexLock(mutex); /* lock shared memory */
101 printf("Ci sono %d file dati\n", shmptr->tot_regular);
102 printf("Ci sono %d directory\n", shmptr->tot_dir);
103 printf("Ci sono %d link\n", shmptr->tot_link);
104 printf("Ci sono %d fifo\n", shmptr->tot_fifo);
105 printf("Ci sono %d socket\n", shmptr->tot_sock);
106 printf("Ci sono %d device a caratteri\n", shmptr->tot_char);
107 printf("Ci sono %d device a blocchi\n", shmptr->tot_block);
108 printf("Totale %d file, per %d byte\n",
109 shmptr->tot_files, shmptr->tot_size);
110 MutexUnlock(mutex); /* unlock shared memory */
113 * routine to print usage info and exit
116 printf("Program myls: list file in a directory \n");
118 printf(" myls [-h] dirname \n");
119 printf(" -h print this help\n");