sending a signal to a background process

感情迁移 提交于 2019-12-22 10:07:38

问题


Which signal should I send to a background process to move it foreground? SIGTTIN, SIGTOU or...?


回答1:


gurudoglu. I think your request's response is here :

  • http://en.wikipedia.org/wiki/SIGCONT
  • http://en.wikipedia.org/wiki/SIGTTIN
  • http://en.wikipedia.org/wiki/SIGTTOU



回答2:


It's not signals which directly control whether jobs are foreground or background. The jobs are under the control of a shell (usually).

For example, under bash, if you execute:

pax> sleep 3600 &
pax> jobs

you will see output like:

[1]+  Running                 sleep 3600 &

Then, you can bring that job back into the foreground by using:

pax> fg %1
sleep 3600

(and the terminal waits).

Using CTRLZ does send a signal to the process (SIGSTOP) as well as putting it into the background but the only signal that can change that is SIGCONT (to continue):

pax> fg %1
sleep 3600
^Z
[1]+  Stopped                 sleep 3600
pax> jobs
[1]+  Stopped                 sleep 3600
pax> kill -CONT %1
pax> jobs
[1]+  Running                 sleep 3600 &

That will instruct the process to start running again but it doesn't bring it into the foreground. For that, you need the fg command.

It's probably best to think of signals (which affect the process) and foreground/background (which affect the shell that started the process by determining whether it waits for it, amongst other things) separately.




回答3:


There is no way (In any OS I know of yet) to use a signal to bring a process to the foreground.

I believe you can only bring a process to the foreground using fg

Foreground is only relevant in the context of a console, and a signal cannot tell the process what console to foreground to...




回答4:


Assuming you are on Unix and started the process from a shell you could type the following

  • Stop Process :: ^Z
  • Move process into background :: bg
  • Move back into foreground :: fg


来源:https://stackoverflow.com/questions/1844232/sending-a-signal-to-a-background-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!