易截截图软件、单文件、免安装、纯绿色、仅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编程(六) L2CAP编程实例

例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
 如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......

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

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

[转]Linux 2.6.19.x 内核编译配置选项简介

Linux 2.6.19.x 内核编译配置选项简介 作者:金步国 版权声明 本文作者是一位自由软件爱好者,所以本文虽然不是软件,但是本着 GPL 的精神发布。任何人都可以自由使用、转载、复制和再分发,但必须保留作者署名,亦不得对声明中的任何条款作任何形式的修改,也不得附加任何其它条件。您可以自由链接、下载、传播此文档 ......

Linux下PCI设备驱动程序开发


 
 
PCI是一种广泛采用的总线标准,它提供了许多优于其它总线标准(如EISA)的新特性,目前已经成为计算机系统中应用最为广泛,并且最为通用的总线标准。Linux的内核能较好地支持PCI总线,本文以Intel 386体系结构为主,探讨了在Linux下开发PCI设备驱动程序的基本框架。
一、PCI总线系统体系结构
PCI是外围 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号