易截截图软件、单文件、免安装、纯绿色、仅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 zImage生成过程详解


内核编译完成后会生成zImage内核镜像文件。关于bootloader加载zImage到内核,并且跳转到zImage开始地址运行zImage的过程,相信大家都很容易理解。但对于zImage是如何解压的过程,就不是那么好理解了。本文将结合部分关键代码,讲解zImage的解压过程。
  先看看zImage的组成吧。在内核编译完成后会在arch/arm/boot/下生 ......

Linux下ps命令详解


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

linux 2.6源代码情景分析笔记之内存2

linux中的段机制:
在linux中,逻辑地址到物理地址,是经过分段单元->分页单元这两个部分的转换来完成的。其中逻辑地址由段标识符和指定段内相对地址的偏移量。前者16位长的字段(段选择符segment selector),后者是32位长的字段。
段选择符的构成:
15-3(index)指定了放在GDT或者LDT中的相应段描述符的入口
2(TL- ......

linux文件系统基础知识

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