简体   繁体   中英

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.

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); , 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. Some syscalls are restarted automatically.

  • The process is disk-waiting (state D), eg waiting for buffer/page-in:

    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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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