C语言 如何向C中的进程发送信号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7696925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 09:51:27  来源:igfitidea点击:

How to send a signal to a process in C?

csignals

提问by Samantha Catania

I need to send a signal to a process and when the process receives this signal it does some things, how is this best achieved in C?

我需要向一个进程发送一个信号,当该进程收到这个信号时它会做一些事情,这在 C 中如何最好地实现?

回答by R.. GitHub STOP HELPING ICE

The way to send a signal to a process is kill(pid, signal);However, you should be aware that signals are not a robust means of inter-process communication except for parent-to-direct-child messages due to inherent race conditions. Pipes, files, directories, named semaphores, sockets, shared memory, etc. all provide greatly superior approaches to inter-process communication.

向进程发送信号的方式是kill(pid, signal);但是,您应该意识到信号并不是一种可靠的进程间通信方式,除了由于固有的竞争条件而导致的父级到直接子级的消息。管道、文件、目录、命名信号量、套接字、共享内存等都为进程间通信提供了非常优越的方法。

回答by wildplasser

If you happen to be on one of the Unix variants, the following man pages will help:

如果您碰巧使用其中一种 Unix 变体,以下手册页将有所帮助:

man 2 kill
man 2 signal
man 2 sigvec