易截截图软件、单文件、免安装、纯绿色、仅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 2.6.19.x 内核编译配置选项简介

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

Linux下ps命令详解


linux上进程有5种状态:
1. 运行(正在运行或在运行队列中等待)
2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号)
3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有中断发生)
4. 僵死(进程已终止, 但进程描述符存在, 直到父进程调用wait4()系统调用后释放)
5. 停止(进程收到SIGSTOP, SIGSTP, ......

Linux下查看CPU使用率!

Linux下查看CPU使用率!
2008年03月20日 星期四 下午 07:02
  在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要。在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况。运行 top 命令后,CPU 使用状态会以全屏的方式显示,并且会处在对话的模式 -- 用基于 top 的命令,可以控制显 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号