#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#define BLOCK_PROCESS_PID 96
int main()
{
if(kill(BLOCK_PROCESS_PID,SIGSTOP) < 0) {
fprintf(stderr,"error occurs when trying to block the specified process. ");
exit(0);
}
printf("sleep for 10 seconds to view the result. ");
sleep(10);
printf("wake up to view the result. ");
if(kill(BLOCK_PROCESS_PID,SIGCONT) < 0) {
fprintf(stderr,"error occurs when trying to awake the process. ");
exit(0);
}
return 1;
}
#include <sys/types.h>
#include <signal.h>
#define BLOCK_PROCESS_PID 96
int main()
{
if(kill(BLOCK_PROCESS_PID,SIGSTOP) < 0) {
fprintf(stderr,"error occurs when trying to block the specified process. ");
exit(0);
}
printf("sleep for 10 seconds to view the result. ");
sleep(10);
printf("wake up to view the result. ");
if(kill(BLOCK_PROCESS_PID,SIGCONT) < 0) {
fprintf(stderr,"error occurs when trying to awake the process. ");
exit(0);
}
return 1;
}
本文提供了一个使用C语言通过send信号来暂停(SIGSTOP)和继续(SIGCONT)指定进程ID的示例代码。该程序首先尝试将指定进程挂起,然后等待10秒后将其唤醒。
230

被折叠的 条评论
为什么被折叠?



