LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 824|回复: 1

请问信号是如何产生的?

[复制链接]
发表于 2007-5-9 14:16:06 | 显示全部楼层 |阅读模式
本人在学习gdbserver的代码,由于本人在linux是一个尚未入门的新手,所以遇到了很多困难,我一般采取一边上网查资料,一边把自己的立即注释上去,虽然可能是错的,嘻嘻。
但是还是有许多不理解的地方,希望大家能帮帮我,先谢谢了。

  1. static unsigned char
  2. linux_wait (char *status)
  3. {
  4.   int w;
  5.   struct thread_info *child = NULL;

  6. retry:
  7.   /* If we were only supposed to resume one thread, only wait for
  8.      that thread - if it's still alive.  If it died, however - which
  9.      can happen if we're coming from the thread death case below -
  10.      then we need to make sure we restart the other threads.  We could
  11.      pick a thread at random or restart all; restarting all is less
  12.      arbitrary.  */
  13.   fprintf(stderr,"cont_thread = %d\n",cont_thread);
  14.   if (cont_thread > 0)
  15.     {
  16.       child = (struct thread_info *) find_inferior_id (&all_threads,
  17.                                                        cont_thread);

  18.       /* No stepping, no signal - unless one is pending already, of course.  */
  19.       if (child == NULL)
  20.         {
  21.           struct thread_resume resume_info;
  22.           resume_info.thread = -1;
  23.           resume_info.step = resume_info.sig = resume_info.leave_stopped = 0;
  24.           linux_resume (&resume_info);
  25.         }
  26.     }

  27.   /*使能异步阻塞处理:置标志async_io_enabled为1,指定对信号SIGIO的处理*/
  28.   /*这个信号是如何产生的?可能是客户端发送连接请求或发送数据时产生的?*/
  29.   enable_async_io ();
  30.   /*解除对SIGSIO信号的阻塞*/
  31.   unblock_async_io ();
  32.   w = linux_wait_for_event (child);
  33.    /*停止所有进程,发送SIGSTOP信号*/
  34.   stop_all_processes ();
  35.   /*非使能异步阻塞处理主要就是忽略对SIGIO信号的处理*/
  36.   disable_async_io ();

  37.   /* If we are waiting for a particular child, and it exited,
  38.      linux_wait_for_event will return its exit status.  Similarly if
  39.      the last child exited.  If this is not the last child, however,
  40.      do not report it as exited until there is a 'thread exited' response
  41.      available in the remote protocol.  Instead, just wait for another event.
  42.      This should be safe, because if the thread crashed we will already
  43.      have reported the termination signal to GDB; that should stop any
  44.      in-progress stepping operations, etc.

  45.      Report the exit status of the last thread to exit.  This matches
  46.      LinuxThreads' behavior.  */

  47.   if (all_threads.head == all_threads.tail)
  48.     {
  49.       if (WIFEXITED (w))
  50.         {
  51.           fprintf (stderr, "\nChild exited with retcode = %x \n", WEXITSTATUS (w));
  52.           *status = 'W';
  53.           clear_inferiors ();
  54.           free (all_processes.head);
  55.           all_processes.head = all_processes.tail = NULL;
  56.           return ((unsigned char) WEXITSTATUS (w));
  57.         }
  58.       else if (!WIFSTOPPED (w))
  59.         {
  60.           fprintf (stderr, "\nChild terminated with signal = %x \n", WTERMSIG (w));
  61.           *status = 'X';
  62.           clear_inferiors ();
  63.           free (all_processes.head);
  64.           all_processes.head = all_processes.tail = NULL;
  65.           return ((unsigned char) WTERMSIG (w));
  66.         }
  67.     }
  68.   else
  69.     {
  70.       if (!WIFSTOPPED (w))
  71.         goto retry;
  72.     }

  73.   *status = 'T';
  74.   return ((unsigned char) WSTOPSIG (w));
  75. }
复制代码

我想问的是sigio信号是如何产生的,如果我是主机与gdbserver通讯的话,何时产生sigio信号,是谁产生的?还有就是大家都说sigint是键盘中断,这个中断又是如何和sigint信号挂上钩的?我问的问题可能比较弱,别笑,我刚学。。。在此拜谢了
 楼主| 发表于 2007-5-11 08:01:13 | 显示全部楼层
等了几天了,自己顶一下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表