在ctrl+C和ctrl+z上的C++SIGINT和SIGSTP
C++ SIGINT and SIGSTP over ctrl+c and ctrl+z
我在一个shell上写东西,想要实现信号 这是我到目前为止的代码: 我不知道如何在代码中实现SIGSTP和SIGINT信号。SIGSTP
和SIGINT
。当用户启动一个新进程并按下CTRL+C时,它应该向该进程发送一个SIGINT,当按下CTRL+Zstring inputNew = input;
vector<char*> arguments;
size_t lastChar = 0;
for(int i = 0; i < input.size(); i++)
{
char& c = input[i];
if((c == ' ' || c == 't'||c == 'n') && lastChar != i)
{
c = ' ';
arguments.push_back(&input[0] + lastChar);
lastChar = i+1;
}
}
bool checkIfBackground(string & input)
{
size_t lastChar = input.size() - 1;
if(input[lastChar] == '&')
{
return true;
}
return false;
}
if((pid = fork()) < 0) {
exit(1);
} else if(pid == 0) {
execvp(arguments[0], &arguments[0]);
exit(1);
} else if(checkIfBackground(inputNew) == false) {
int status;
pid_t pid_r;
if(waitpid(pid, &status, 0) < 0) {
cout << "PID not known!";
}
} else {
cout << "Prozess is waiting in the background." << endl;
}
请参阅sigaction(2)
手册页面。它解释了如何设置实现一个信号处理程序。
请注意,信号处理程序是异步的。这有许多含义。阅读手册页面,花点时间在谷歌上。
- boost::asio 无法捕获 SIGINT
- 脚本中缺少SIGINT?
- 如何使用 SIGINT 在第二个线程中断 getchar
- 调用系统(3)时忽略了SIGINT
- 在 SIGINT 上优雅地关闭
- 在接收 SIGINT 操作时适当地关闭多线程 c++ 应用程序
- 程序结构以捕获SIGINT并在C++中调用析构函数
- 如何使用 sigaction() 拦截 SIGINT
- Visual C++2015中的SIGINT处理程序重置
- 如何防止在C++中使用 popen() 打开的进程接收 SIGINT 信号?
- 我可以将参数传递给SIGINT吗
- 如何仅在C中向后台进程发送SIGINT
- sigaction SIGINT,程序在 & (background) 中运行,没有得到信号
- 将 std::string 转换为大写时的 SIGINT
- 使用 select() 时无法捕获 SIGINT 信号
- 执行std::thread::join()时的SIGINT
- 在ctrl+C和ctrl+z上的C++SIGINT和SIGSTP
- c++ strcpy SIGINT error
- SIG_IGN忽略SIGINT信号失败
- SIGINT signal()/sigaction in C++