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 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告, 包 ...
随机推荐
- zip与unzip
- R语言排序函数汇总
总结: 1.sort是直接对向量排序,返回原数值: 2.order先对数值排序,然后返回排序后各数值的索引: 3.rank返回原数据各项排名,有并列的情况: 4.arrange是dplyr包中的,可对 ...
- LeetCode119.杨辉三角 II
119.杨辉三角 II 描述 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例 输入: 3 输出: [1,3,3,1] 进阶 ...
- 洛谷 P3380 【模板】二逼平衡树(树套树)
题面 luogu 题解 2019年AC的第一道题~~ 函数名命名为rank竟然会ce 我写的是树状数组套值域线段树(动态开点) 操作1:询问\(k\)在\([l-r]\)这段区间有多少数比它小,再加\ ...
- Web下TreeView同一节点连续点击,只执行一次SelectedNodeChanged的解决
Web下TreeView同一节点连续点击,只执行一次SelectedNodeChanged的解决 http://blog.csdn.net/net_boy/archive/2009/11/05/477 ...
- 115th LeetCode Weekly Contest Check Completeness of a Binary Tree
Given a binary tree, determine if it is a complete binary tree. Definition of a complete binary tree ...
- python 文件处理(基础字符)
基于字符read & write 最基本的文件操作当然就是在文件中读写数据.这也是很容易掌握的.现在打开一个文件以进行写操作: 1. fileHandle = open ( 'test.txt ...
- C++ GUI Qt4编程(10)-3.4spreadsheet
1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...
- 如何在新导入的python项目中一次性生成依赖的第三方库
requirements.txt用来记录项目所有的依赖包和版本号,只需要一个简单的pip命令就能完成. pip freeze >requirements.txt 然后就可以用 pip insta ...
- javascript格式化时间(几秒钟前,几分钟前,几小时前,几天前...)
beautify_time: function(timestamp) { var mistiming = Math.round(new Date() / 1000) - timestamp; var ...