简体   繁体   English

程序收到SIGTSTP信号时会发生什么

[英]What happens when a program receives SIGTSTP signal

I wrote a program in C and I need to handle ctrl + z and the corresponding signals SIGTSTP and SIGCONT. 我用C语言编写了一个程序,需要处理ctrl + z和相应的信号SIGTSTP和SIGCONT。

What happens to my variables and my process after the signal is received? 收到信号后,我的变量和过程会怎样?
After the signal is handled through the signal handler signal(SIGCONT, &sig_handler); 通过信号处理程序signal(SIGCONT, &sig_handler);处理signal(SIGCONT, &sig_handler); , what happens to my process? ,我的流程会怎样?

There are (at least) three possible situations: 至少有三种可能的情况:

  • The process is currently running in userspace: 该进程当前正在用户空间中运行:

    In this case, the process is preempted (a similar way as when its timeslice ran out when multitasking) and not considered for rescheduling until it is resumed. 在这种情况下,该进程将被抢占(类似于多任务处理时其时间片用完的方式),直到恢复后才考虑重新安排该进程。

  • The process is currently waiting in a syscall: 该进程当前正在系统调用中等待:

    Usually the syscall is interrupted and the process is not considered for scheduling until it is resumed. 通常,系统调用会中断,并且直到恢复后才考虑对该进程进行调度。 When it is resumed, some syscalls return -EINTR and have to be restarted. 恢复后,某些系统调用将返回-EINTR ,必须重新启动。 Some syscalls are restarted automatically. 某些系统调用会自动重新启动。

  • The process is disk-waiting (state D), eg waiting for buffer/page-in: 进程正在等待磁盘(状态D),例如,等待缓冲区/页面进入:

    The signal is set pending, but is not delivered until the operation finished. 该信号被设置为挂起,但直到操作完成才传递。 After that, it is the same as one of the situations above. 之后,它与上述情况之一相同。

Usually this all is quite transparent to the process itself. 通常,所有这些对于过程本身都是相当透明的。

This is the same for the default action of SIGTSTP and SIGSTOP (the latter cannot be caught or ignored, however). 这与SIGTSTPSIGSTOP的默认操作相同(但是不能捕获或忽略后者)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM