程序员,中国最值得同情的职业么? 04月25日

程序员,中国最值得同情的职业么?

世界首富Bill Gates是程序员、中国首富李彦宏也是程序员,但是,这依旧没法改变中国程序员苦逼的形象。 今 [...]

Webkit内核探究【2】——Webkit CSS实现【转】 04月06日

Webkit内核探究【2】——Webkit CSS实现【转】

出处:http://www.cnblogs.com/jyli/archive/2010/01/31/16603 [...]

Webkit内核探究【1】——Webkit简介【转】 04月06日

Webkit内核探究【1】——Webkit简介【转】

出处:http://www.cnblogs.com/jyli/archive/2010/01/31/16603 [...]

用GDB调试PHP程序[转] 03月28日

转载自:http://www.sulabs.net/?p=40

我们先想办法重现一下Segmentation fault现象,下面我们先使用Shell的方式来试验,编写demo.sh脚本:

#!/bin/bash
kill -s SEGV $$

其中$$就是脚本的进程号,SEGV信号的作用等同于Segmentation fault,整句基本意思就是让自己崩溃。

保存好,并且加上执行权限:chmod +x demo.sh (更多…)

分布式计算框架 Fourinone[转] 03月15日

FourInOne(中文名字“四不像”)是一个四合一分布式计算框架,在写这个框架之前,我对分布式计算进行了长时间的思考,也看了老外写的其他开源框架,当我们把复杂的hadoop当作一门学科学习时,似乎忘记了我们想解决问题的初衷:我们仅仅是想写个程序把几台甚至更多的机器一起用起来计算,把更多的cpu和内存利用上,来解决我们数量大和计算复杂的问题,当然这个过程中要考虑到分布式的协同和故障处理。如果仅仅是为了实现这个简单的初衷,为什么一切会那么复杂,我觉的自己可以写一个更简单的东西,它不需要过度设计,只需要看上去更酷一点,更小巧一点,功能更强一点。于是我将自己对分布式的理解融入到这个框架中,考虑到底层实现技术的相似性,我将 Hadoop,Zookeeper,MQ,分布式缓存四大主要的分布式计算功能合为一个框架内,对复杂的分布式计算应用进行了大量简化和归纳。 (更多…)

在C里面嵌入Lua的过程[lua研究二] 03月09日

偶遇一个事情,需要在C里面嵌入Lua代码,这真是痛苦了我好久….

不知道为啥lua默认编译没有生成.so 的动态链接库,需要修改Makefile生成liblua.so,我用的版本是5.2

一、先修改根目录的 Makefile
修改一行

TO_LIB= liblua.a liblua.so

二、再修改src的Makefile
注意,请搜索关键字,第二行是需要修改的,第一行,和第三行是粘贴的,至于粘贴的位置嘛,你看样子比较像的就粘贴一起吧
第三行的开始是tab键

LUA_SO=liblua.so
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO)
$(LUA_SO): $(CORE_O) $(LIB_O)
$(CC) -o $@ -shared $? -ldl -lm

然后编译,安装,ldconfig

make linux
make install

在/etc/ld.so.conf中加入一行
/usr/local/lib/
然后执行
/sbin/ldconfig
重新加载动态链接库。

三、敲两段代码
luadd.c

#include
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

/* the Lua interpreter */
lua_State* L;

int luaadd ( int x, int y )
{
int sum;

/* the function name */
lua_getglobal(L,"add");

/* the first argument */
lua_pushnumber(L, x);

/* the second argument */
lua_pushnumber(L, y);

/* call the function with 2
arguments, return 1 result */
lua_call(L, 2, 1);
//lua_pcall(L, 2, 1,0);

/* get the result */
sum = (int)lua_tointeger(L, -1);
lua_pop(L, 1);

return sum;
}

int main ( int argc, char *argv[] )
{
int sum;

/* initialize Lua */
//L = lua_open();
L = luaL_newstate();

/* load Lua base libraries */
//luaL_openlibs(L);
luaopen_base(L);

/* load the script */
(void)luaL_dofile(L, "add.lua");

/* call the add function */
sum = luaadd( 10, 15 );

/* print the result */
printf( "The sum is %d\n", sum );

/* cleanup Lua */
lua_close(L);

/* pause */
//printf( "Press enter to exit..." );
//getchar();

return 0;
}

lua代码 add.lua

function add(x,y)
return x+y
end

四、当然是gcc了

gcc luadd.c -llua -ldl -g

五、不出意外的话,当然是出现结果

the sum is 25

希望大家这过程顺利

Lua在linux下的安装[Lua研究一] 03月08日


wget http://www.lua.org/ftp/lua-5.2.0.tar.gz
tar zxvf lua-5.2.0.tar.gz
make linux
make install

然后lua就安装好了,简单快捷

print(“a”);

print(“hello”);

Facebook Scribe介绍【转】 03月06日

Facebook Scribe介绍

——————-

1. 介绍

Scribe是Facebook一个开源的实时分布式日志收集系统。它提高了大规模日志收集的可靠性和可扩展性。你可以在不同的节点上安装Scribe服务,然后这些服务会把收集到的信息发布到中心的服务集群上去。当中心服务不可得到时,本地的Scribe服务会暂时把收集到的信息存储到本地,等中心服务恢复以后再进行信息的上传。中心服务集群可以把收集到的信息写入本地磁盘或者分布式文件系统上,如hdfs,或者分发到另一层的Scribe服务集群上去。

Scribe提供了一种无阻塞的thrift服务,底层依赖libevent库和thrift库的支持。 (更多…)

Gdb调试多进程程序 02月14日

最近需要调试memcached等程序,发现看代码是一件很悲剧的事情,最后还是借助gdb吧,这个算一劳永逸了。

Gdb调试多进程程序

程序经常使用fork/exec创建多进程程序。多进程程序有自己独立的地址空间,这是多进程调试首要注意的地方。Gdb功能强大,对调试多线程提供很多支持。

方法1:调试多进程最土的办法:attach pid

Attach是调试进程的常用办法,只要有可执行程序以及相应PID,即可工作。当然,为方便调试,可以在进程启动后,设定sleep一段时间,如30s,这样即可有充足的时间来attach。

方法2: set follow-fork-mode child + main断点

当设置set follow-fork-mode child,gdb将在fork之后直接执行子进程,知道碰到断点后停止。如何设置子进程的断点呢?在父进程中是无法知道子进程的地址空间的(只有等程序载入后方可知)。Gdb提供一个很方便的机制:main函数的断点将被子进程继承(毕竟main是任何程序的入口)。

注意:程序在main停下后,可尝试设置断点。断点是否有效,取决于gdb是否已经载入目标程序的地址空间。

方法3: set follow-fork-mode child + catch exec

Cache点是一种特殊的breakpoint。Gdb能够catch的事件很多,如throw/catch/exception/syscall/exec/fork/vfork等。其中和多进程关系最大的就是exec/fork事件。

举例:

GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
(gdb) catch exec
Catchpoint 1 (exec)
(gdb) set follow-fork-mode child
(gdb) r  -d ***
Catchpoint 1 (exec'd /****/binary), 0x0000003c68800a70 in _start ()
from /lib64/ld-linux-x86-64.so.2
(gdb) bt
#0  0x0000003c68800a70 in _start () from /lib64/ld-linux-x86-64.so.2
#1  0x0000000000000003 in ?? ()
#2  0x00007fff65c6e85a in ?? ()
#3  0x00007fff65c6e85d in ?? ()
#4  0x00007fff65c6e860 in ?? ()
(gdb) b lib.cc:8720
No symbol table is loaded.  Use the "file" command.
(gdb) c
Continuing
(gdb) bt
#0  0x0000003c68800a70 in _start () from /lib64/ld-linux-x86-64.so.2
#1  0x0000000000000002 in ?? ()
#2  0x00007fff1af7682a in ?? ()
#3  0x0000000000000000 in ?? ()
(gdb)  b lib.cc:8720
Breakpoint 2 at 0x15f9694: file lib.cc, line 8720.
(gdb) c
Continuing.
[Thread debugging using libthread_db enabled]
[Thread 0x40861940 (LWP 12602) exited]
[Switching to process 12630]
0x0000003c6980d81c in vfork () from /lib64/libpthread.so.0
Warning:
Cannot insert breakpoint 2.
Error accessing memory address 0x15f9694: Input/output error.
(gdb) bt
#0  0x0000003c6980d81c in vfork () from /lib64/libpthread.so.0
#1  0x000000000040c3fb in ?? ()
#2  0x00002adeab604000 in ?? ()
#3  0x01000000004051ef in ?? ()
#4  0x00007fffff4a42f0 in ?? ()
#5  0x686365746e6f6972 in ?? ()
#6  0x0000000d0000000c in ?? ()
#7  0x0000000b0000000a in ?? ()
#8  0x0000000000000000 in ?? ()
(gdb) delete 2  --此处当breakpoint无效时,必须删除,否则程序无法继续
(gdb) c
Continuing.
[New process 12630]
Executing new program: /****/binary
warning: Cannot initialize thread debugging library: generic error
[Switching to process 12630]
Catchpoint 1 (exec'd /****/binary), 0x0000003c68800a70 in _start ()
from /lib64/ld-linux-x86-64.so.2
(gdb) bt
#0  0x0000003c68800a70 in _start () from /lib64/ld-linux-x86-64.so.2
#1  0x0000000000000009 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) b lib.cc:8720
Breakpoint 4 at 0x15f9694: file lib.cc, line 8720.
(gdb) b type.cc:32
Breakpoint 5 at 0x1693050: file type.cc, line 32.
(gdb) c
Continuing.
(gdb)  -- 和正常程序调试一样

说明:catch exec后,程序将在fork/vfork/exec处停下。并非每次停下后,设置断点都是有效的。如提供断点无效,需要删除,否则程序无法继续。要能够在新进程中设置断点,一定要等到新进程的地址空间被载入后,设置断点是才有效(exec将改变原程序的地址空间)。上述例子,主要想展示如何对新进程设置断点!

注意:
1)程序地址非常重要(代码和数据地址一样重要)。使用gdb时,多多注意和利用地址信息。
2)On some systems, when a child process is spawned by vfork, you cannot debug the child or parent until an exec call completes.

方法4info inferiors/inferiors inferiors

设置set detach-on-fork off/set follow-exec-mode new

If you choose to set `detach-on-fork’ mode off, then gdb will retain control of all forked processes (including nested forks). You can list the forked processes under the control of gdb by using the info inferiors command, and switch from one fork to another by using the inferior command.

所使用的gdb不支持set detach-on-fork off/set follow-exec-mode new/info inferiors。不清楚。

写给2012 12月31日

写给2012

还有两个小时就2012了,我们真的离死不远 了。 很久不写博客了,还是想在2011留下点什么。 突然发现没什么 [...]

第 3 页,共 11 页12345...10...最旧 »