linux c 监控目录
static void* thread_monitor(void* args)
{
pthread_detach(pthread_self());
int fd;
int wd;
int len;
int nread;
char buf[BUFSIZ];
char cmd[256] = {0};
struct inotify_event *event;
fd = inotify_init();
wd = inotify_add_watch(fd,cups_backend, IN_DELETE|IN_MOVED_TO|IN_MOVED_FROM|IN_CREATE);
if(wd < 0)
{
//LOG_ERR("inotify_add_watch failed\n");
close(fd);
return NULL;
}
while((len = read(fd,buf,sizeof(buf) - 1 )) > 0)
{
nread = 0;
while(len > 0)
{
event = (struct inotify_event *)&buf[nread];
if((event->mask & IN_DELETE) && strcmp("hook_backend",event->name) ==0)
{
memset(cmd,0,sizeof(cmd));
snprintf(cmd,sizeof(cmd),"cp /opt/CEMS/bin/hook_backend %s",cups_backend);
system(cmd);
//chmod(full_hook_backend,0500);
}
std::set<std::string>::iterator iter;
iter = device_list.find(event->name);
std::set<std::string>::const_iterator it;
for(it=device_list.begin();it!=device_list.end();it++)
{
//printAudit_log_run_info((*it).c_str());
//printAudit_log_run_info(event->name);
}
if(((event->mask & IN_DELETE)||(event->mask & IN_MOVED_FROM)||(event->mask & IN_CREATE) )&& iter!=device_list.end())
{
memset(cmd,0,sizeof(cmd));
snprintf(cmd,sizeof(cmd),"%s%s",cups_backend,event->name);
symlink(full_hook_backend,cmd);
}
if((event->mask & IN_MOVED_TO) || ((event->mask & IN_CREATE)))
{
//get_backend_info();
std::set<std::string>::iterator it;
deal_backend();
// it = device_list.find(event->name);
// if(it!= device_list.end())
// {
// deal_backend();
// }
}
nread = nread + sizeof(struct inotify_event) + event->len;
len = len - sizeof(struct inotify_event) - event->len;
}
}
inotify_rm_watch(fd,wd);
close(fd);
return NULL;
}
创建线程
bool printer_ctrl_worker()
{
printer_ctrl_init();
if(pid_monitor == 0)
{
if(pthread_create(&pid_monitor,NULL,thread_monitor,NULL))
{
pid_monitor = 0;
}
}
if(!check_hook_backend())
{
//chmod(full_hook_backend,0500);
}
return true;
}
#include <stdlib.h>
#include <vector>
#include <string>
#include <set>
#include <functional>
#include <sys/inotify.h>
#include <string.h>
#include <dirent.h>
#include <list>
#include <sys/stat.h>
#include <time.h>
#include <pthread.h>
#include <signal.h>
linux c 监控目录的更多相关文章
- linux 进程监控
linux 进程监控 supervise Supervise是daemontools的一个工具,可以用来监控管理unix下的应用程序运行情况,在应用程序出现异常时,supervise可以重新启动指定程 ...
- linux系统监控常用工具
linux系统监控常用工具 一.系统核心工具包(coreutils) 1./bin/df 报告系统的磁盘空间用量 df -h 显示磁盘分区fdisk -l 2./bin/uname 显示系统信息 u ...
- Linux/Centos笔记目录
Linux介绍 Linux入门--个人感想 Google怎么用linux 初入Linux Windows XP硬盘安装Ubuntu 12.04双系统图文详解 实例讲解虚拟机3种网络模式(桥接. ...
- Linux开源监控平台归总
Linux开源监控平台归总 Cacti 偏向于基础监控.成图非常漂亮,需要php环境支持,并且需要mysql作为数据存储 Cacti是一个性能广泛的图表和趋势分析工具,可以用来跟踪并几乎可以绘制出任何 ...
- Python监控目录和文件变化
一.os.listdir import os, time path_to_watch = "." before = dict ([(f, None) for f in os.lis ...
- Linux系统资源监控--linux命令、nmon和spotlight
前言: 系统资源监控一般监控系统的CPU,内存,磁盘和网络.系统分为windows和Linux.本篇主要记录Linux. Linux系统资源监控常用命令及工具 一.常用命令:top.free.iost ...
- Linux未来监控tracing框架——eBPF
Linux未来监控tracing框架--eBPF eBPF源于早年间的成型于 BSD 之上的传统技术 BPF(Berkeley Packet Filter).BPF 的全称是 Berkeley Pac ...
- Linux下监控网卡流量的软件Nload
Linux下监控网卡流量的软件Nload 安装nload: # wget http://www.roland-riegel.de/nload/nload-0.7.2.tar.gz # tar zxvf ...
- linux系统监控sar命令
linux系统监控sar命令详解 sar(System Activity Reporter系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告, 包 ...
随机推荐
- python-day15---面向对象
面向对象零:面向对象的说明: 面向过程和面向对象: 面向对象:一切以对象为中心(解决的问题本身) 面向过程:一切以过程为中心(解决问题的步骤) 面向对象我们用 “ class 类名:” 来表示面向对象 ...
- Visual Studio Ultimate 2013 免费下载地址
ed2k://|file|cn_visual_studio_2010_ultimate_x86_dvd_532347.iso|2685982720|4AE6228933DDE49D9BFA4C3467 ...
- bzoj1934 Vote 善意的投票 最小割(最大匹配)
题目传送门 题目大意:很多小朋友,每个小朋友都有自己的立场,赞成或者反对,如果投了和自己立场不同的票会得到一个能量.又有很多朋友关系,如果一个人和他的一个朋友投的票不同,也会得到一个能量,现在问,通过 ...
- F. Clear the String(区间 DP )//每次都删除一个相同字符的子串 , 最小多少次
https://codeforces.com/contest/1132/problem/F 借鉴:https://www.cnblogs.com/chhokmah/p/10508762.html 题意 ...
- 119th LeetCode Weekly Contest Subarray Sums Divisible by K
Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum ...
- SPOJ - FAVDICE 简单期望
dp[0]=0; // rep(i,1,n) dp[i]=(double)(n-i)/n*dp[i-1]+1+(double)(i)/n*dp[i]; // (n-i)/n dp[i]= n-i / ...
- highcharts去掉x轴,y轴,轴线以及刻度
var chart = null; $.getJSON('https://data.jianshukeji.com/jsonp?filename=json/usdeur.json&callba ...
- PIE SDK地图鹰眼图
鹰眼图,是GIS的一个基本功能,在鹰眼图上可以像从空中俯视一样查看地图框中所显示的地图在整个图中的位置,是对全局地图的一种概述表达,能够起到很好的空间提示和导航的作用.网上有很多Arcengine 二 ...
- 转帖 JS的基础语法2
条件语句(if.switch). 循环语句(while.do…while. for … in).跳转语句(break,continue) 1.条件语句 Ø if语句 javascrip中的if语句 v ...
- 单元测试框架AndroidTestCase
我不是讲怎么成为一个安卓测试员,就不写那么多了 就写我们常用的, AndroidTestCase 为一Android平台下通用的测试类,它支持所有JUnit的Assert方法和标准的setUp 和te ...