易截截图软件、单文件、免安装、纯绿色、仅160KB

linux lua

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "include/lua.hpp"
bool g_bQuit = false;
void SignalHandler(int signal)
{
 printf("nanny thread was interrupt by signal\n");
 g_bQuit = true;
}
//for lua
//执行传来的字符串,返回结果
static int NannyCreateProcess(lua_State* L)
{
 const char* param = lua_tostring(L,1);
 int ret = system(param);
 lua_pushnumber(L, ret);
 return 1;
}
void DoLuaCheck(lua_State* L, char* szBuf)
{
 lua_getglobal(L, "NannyCheckPsString");
 lua_pushstring(L, szBuf);
 lua_call(L, 1, 0);
}
void DoLuaReset(lua_State* L)
{
 lua_getglobal(L, "NannyTryReloadProcess");
 lua_call(L, 0, 0);
}
lua_State* InitLua()
{
 lua_State* L = lua_open();
 luaopen_base(L);
 luaL_openlibs(L);
 
 lua_register(L, "NannyCreateProcess", NannyCreateProcess);
 luaL_dofile(L, "nanny.lua");
 return L;
}
bool DoCheck()
{
 int fd[2];
 
 if( pipe(fd) < 0 )
 {
  fprintf(stderr, "failed to create pipe! (%s)\n", strerror(errno));
  return false;
 }
 
 int nRet = fork();
 if( nRet > 0 )
 {
  //读取管道中ps输出
  lua_State* L = InitLua();
  if( L == NULL )
   return false;
  close(fd[1]);
  FILE* fp = fdopen(fd[0], "r");
  if( fp == NULL )
  {
   lua_close(L);
   return false;
  }
  char szBuf[2048] = { 0 };
  while( fgets(szBuf, 2048, fp) != NULL )
  {
   DoLuaCheck(L, szBuf);
   //fprintf(stderr, "-----------%s",szBuf);
   memset(szBuf,  0, 2048);
 


相关文档:

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

Linux设备模型之input子系统详解

一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......

Linux 内存管理 高端内存的映射方式

解释一:
高端内存是指物理地址大于 896M 的内存。
对于这样的内存,无法在“内核直接映射空间”进行映射。
为什么?
因为“内核直接映射空间”最多只能从 3G 到 4G,只能直接映射 1G 物理内存,对于大于 1G 的物理内存,无能为力。
实际上,“内核直接映射空间”也达不到 1G, 还得留点 ......

Linux下查看CPU使用率!

Linux下查看CPU使用率!
2008年03月20日 星期四 下午 07:02
  在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要。在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况。运行 top 命令后,CPU 使用状态会以全屏的方式显示,并且会处在对话的模式 -- 用基于 top 的命令,可以控制显 ......

linux文件系统基础知识

这两天看了一本fedora 6的实践教程,下面是有关linux文件系统知识的学习笔记:
1、linux文件系统分配策略:
    块分配( block allocation ) 和 扩展分配  ( extent allocation )
    块分配:磁盘上的文件块根据需要分配给文件,避免了存储空间的浪费。但当文件扩充时,会造成文件中文件 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号