资源描述:
《天津大学计算机科学与技术-操作系统原理实验2》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、学号:3011216010姓名:罗壹文学院:计算机科学与技术操作系统实验2(一)实验目的完成一个监视指定的若干目录变动情况的(服务)程序。(二)实验内容利用inotify机制进行文件或文件夹的监控。(三)实验结果fileMonitor为程序名称,源码如下:#include#include#include#include#include#include#include#include#
2、include#include#include#include//#define_DEBUG#define_DAEMON#defineEVENT_NUM16#defineBUF_SIZE10240#ifdef_DAEMONchar*fileConf="/etc/fileMonitor.conf";char*fileScan="/etc/fileMonitor.scan";char*fileLog="/etc/fileMonitor.log";#elsechar*file
3、Conf="fileMonitor.conf";char*fileScan="fileMonitor.scan";char*fileLog="fileMonitor.log";第42页共42页学号:3011216010姓名:罗壹文学院:计算机科学与技术#endifstructwd_name{intwd;char*name;};intwd_NUM=0;structwd_name*wd_array;//structstatbuf;//fordetiminethetypeoffile.constintfilenameLen=500;constintfilelis
4、tLen=10000;charfiles[10000][500];charbuffer[BUF_SIZE];charlogmsg[500];FILE*fplog;intfd,wd;char*offset=NULL;structinotify_event*event;intlen,tmp_len;charstrbuf[16];inti=0;intm_argc;char**m_argv;intsleeptime=1;char*event_array[]={"Filewasaccessed","Filewasmodified","Fileattributeswe
5、rechanged","writtablefileclosed","Unwrittablefileclosed","Filewasopened","FilewasmovedfromX","FilewasmovedtoY","Subfilewascreated","Subfilewasdeleted","Selfwasdeleted","Selfwasmoved",第42页共42页学号:3011216010姓名:罗壹文学院:计算机科学与技术"","Backingfswasunmounted","Eventqueuedoverflowed","Filewasi
6、gnored"};intinit(intargc,char**argv);intreadConfig(char*filename);intresetConfig(char*filename);intreadScan(char*filename,intcur);intparseCmd(char*filename,intargc,char**argv);intexecCmd(char**dirs,char**f_files,char**filetypes,intdsize,intfsize,inttsize,char*filename,intflag);//n
7、orecursivelyintexecCmdN(char**dirs,intdsize,char*filename,intcur);//recursivelyintexecCmdR(char**dirs,intdsize,char*filename,intcur);//withfiletypeintexecCmdT(char**dirs,char**filetypes,intdsize,inttsize,char*filename,intcur);//onlyfilesintexecCmdF(char**f_files,intfsize,intcur);c
8、har*getTime(){time_tnow;structtm*