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