Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[Pthread] LinuxÉϳÌÐòµ÷ÊԵĻùʯ(Ò»)

Ô­ÎĵØÖ·£ºhttp://blog.csdn.net/Javadino/archive/2008/09/06/2891413.aspx
Òý×Ó:
1.ÔÚLinuxϵͳÖУ¬½ø³Ì״̬³ýÁËÎÒÃÇËùÊìÖªµÄTASK_RUNNING£¬TASK_INTERRUPTIBLE£¬TASK_STOPPEDµÈ£¬»¹ÓÐÒ»¸öTASK_TRACED¡£Õâ±íÃ÷Õâ¸ö½ø³Ì´¦ÓÚʲô״̬£¿
2.strace¿ÉÒÔ·½±ãµÄ°ïÖúÎÒÃǼǼ½ø³ÌËùÖ´ÐеÄϵͳµ÷Óã¬ËüÊÇÈçºÎ¸ú×Ùµ½½ø³ÌÖ´Ðеģ¿
3.gdbÊÇÎÒÃǵ÷ÊÔ³ÌÐòµÄÀûÆ÷£¬¿ÉÒÔÉèÖöϵ㣬µ¥²½¸ú×Ù³ÌÐò¡£ËüµÄʵÏÖÔ­ÀíÓÖÊÇʲô£¿
ËùÓÐÕâÒ»Çеı³ºó¶¼Òþ²Ø×ÅLinuxËùÌṩµÄÒ»¸öÇ¿´óµÄϵͳµ÷ÓÃptrace().
1.ptraceϵͳµ÷ÓÃ
ptrace
ϵͳµ÷´ÓÃû×ÖÉÏ¿´ÊÇÓÃÓÚ½ø³Ì¸ú×ٵģ¬ËüÌṩÁ˸¸½ø³Ì¿ÉÒÔ¹Û²ìºÍ¿ØÖÆÆä×Ó½ø³ÌÖ´ÐеÄÄÜÁ¦£¬²¢ÔÊÐí¸¸½ø³Ì¼ì²éºÍÌæ»»×Ó½ø³ÌµÄÄں˾µÏñ(°üÀ¨¼Ä´æÆ÷)µÄÖµ¡£Æä»ù
±¾Ô­ÀíÊÇ:
µ±Ê¹ÓÃÁËptrace¸ú×Ùºó£¬ËùÓз¢Ë͸ø±»¸ú×ÙµÄ×Ó½ø³ÌµÄÐźÅ(³ýÁËSIGKILL)£¬¶¼»á±»×ª·¢¸ø¸¸½ø³Ì£¬¶ø×Ó½ø³ÌÔò»á±»×èÈû£¬Õâʱ×Ó½ø³ÌµÄ״̬¾Í»á±»
ϵͳ±êעΪTASK_TRACED¡£¶ø¸¸½ø³ÌÊÕµ½Ðźź󣬾ͿÉÒÔ¶ÔÍ£Ö¹ÏÂÀ´µÄ×Ó½ø³Ì½øÐмì²éºÍÐ޸ģ¬È»ºóÈÃ×Ó½ø³Ì¼ÌÐøÔËÐС£    
    ÆäÔ­ÐÍΪ£º    
    #include <sys/ptrace.h>
    long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
    ptraceÓÐËĸö²ÎÊý:
    1). enum __ptrace_request request£ºÖ¸Ê¾ÁËptraceÒªÖ´ÐеÄÃüÁî¡£
    2). pid_t pid: ָʾptraceÒª¸ú×ٵĽø³Ì¡£
    3). void *addr: ָʾҪ¼à¿ØµÄÄÚ´æµØÖ·¡£
    4). void *data: ´æ·Å¶ÁÈ¡³öµÄ»òÕßҪдÈëµÄÊý¾Ý¡£
ptraceÊÇÈç´ËµÄÇ¿´ó£¬ÒÔÖÁÓÚÓкܶà´ó¼ÒËù³£ÓõŤ¾ß¶¼»ùÓÚptraceÀ´ÊµÏÖ£¬ÈçstraceºÍgdb¡£½ÓÏÂÀ´£¬ÎÒÃǽèÓɶÔstraceºÍgdbµÄʵÏÖ£¬À´¿´¿´ptraceÊÇÈçºÎʹÓõġ£
2. straceµÄʵÏÖ
strace³£³£±»ÓÃÀ´À¹½ØºÍ¼Ç¼½ø³ÌËùÖ´ÐеÄϵͳµ÷Óã¬ÒÔ¼°½ø³ÌËùÊÕµ½µÄÐźš£ÈçÓÐÕâôһ¶Î³ÌÐò£º
HelloWorld.c:
#include <stdio.h>
int main(){
    printf("Hello World!\n");
    return 0;
}
±àÒëºó£¬ÓÃstrace¸ú×Ù£º strace ./HelloWorld
¿ÉÒÔ¿´µ½ÐÎÈç:
execve("./HelloWorld", ["./HelloWorld"], [/* 67 vars */]) = 0
brk(0)          &


Ïà¹ØÎĵµ£º

Linux ϱàÒëhello world µÄC ÓïÑÔ³ÌÐò

±¾À´ÎÒÓõÄÊÇÕâÑùµÄ³ÌÐò
# include <iostream.h>
int main(void)
{
  int i,j;
  j=0;
  i=j+1;
  cout<<"hello world!"<<endl;
  cout<<"the result is"<<i<<endl;
  return 0;
}
ÀûÓÃg++ -o test test.cpp¡£µ«ÊÇÕâÑùÊÇÓдíÎóµÄ£¬ÌáʾÎÞ·¨´ ......

ǶÈëʽLinuxÎïÀíÄÚ´æÓ³Éä

The physical memory map for Linux is completely independent from the virtual map and is designed to maximize contiguous space. Given that the kernel image will always be at the start of DRAM, the Linux kernel maximizes contiguous space by allocating runtime memory from the end of physical DRAM movin ......

linuxÐźűà³Ìʵ¼ù

¼òµ¥µÄ˵£¬ÐźžÍÊÇÔÚÈí¼þ²ã´ÎÉ϶ÔÖжϻúÖƵÄÒ»ÖÖÄ£Ä⣬ÊÇÒ»ÖÖÒ첽ͨÐÅ·½Ê½¡£Ëü¿ÉÒÔʵÏÖÄں˽ø³ÌºÍÓû§½ø³ÌÖ®¼äµÄ½»»¥¡£ÊµÏÖ·½Ê½ÊÇ£¬ÔÚÈκÎʱºò·¢¸ø
ijһ½ø³Ì£¬Èç¹û¸Ã½ø³ÌûÓд¦ÓÚÖ´ÐÐ̬£¬Ôò¸ÃÐźÅÓÉÄں˱£´æ£¬Ö±µ½¸Ã½ø³Ì»Ö¸´Ö´ÐÐÔÙ´«µÝ¸øËüΪֹ¡£Èç¹ûÒ»¸öÐźŽø³ÌÉèÖÃΪ×èÈû£¬Ôò¸ÃÐźŵĴ«µÝ±»ÑÓ³Ù£¬Ö±µ½
Æä×èÈû±»È¡Ïûʱ ......

LinuxÎļþ²éÕÒÃüÁîfind,xargsÏêÊö

ÕªÒª£º ±¾ÎÄÊÇfind ÃüÁîµÄÏêϸ˵Ã÷£¬¿É¹óµÄÊÇÕë¶Ô²ÎÊý¾ÙÁ˺ܶàµÄʵÀý£¬´óÁ¿µÄÀýÖ¤£¬ÈóõѧÕ߸üΪÈÝÒ×Àí½â£»±¾ÎÄÊÇzhyflyÐÖÌùÔÚÂÛ̳ÖУ»ÎÒ¶Ô±¾ÎĽøÐÐÁËÔÙ´ÎÕûÀí£¬Îª·½±ã´ó¼ÒÔĶÁ£»
Ŀ¼
°æȨÉùÃ÷
Ç°ÑÔ£º¹ØÓÚfindÃüÁî
Ò»¡¢find ÃüÁî¸ñʽ
1¡¢findÃüÁîµÄÒ»°ãÐÎʽΪ£»
2¡¢findÃüÁîµÄ²ÎÊý£»
3¡¢findÃüÁîÑ¡Ï
4¡¢Ê¹ÓÃexe ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ