signals

How to enable SIGINT signal for system() call in a pthread in C?

我的梦境 提交于 2021-02-08 11:55:25
问题 The below manual on system() says it blocks SIGINT and SIGQUIT signal for any binary program run through system() call. https://man7.org/linux/man-pages/man3/system.3.html#:~:text=The%20system()%20library%20function,the%20command%20has%20been%20completed. Psedo Code: thread_1() { ... system("binary application"); } main() { ... pid = pthread_create(thread_1); pthread_cancel(pid); } pthread_cancel issues SIGINT to thread 1 which kill the thread 1, but not the binary application. How to make

Get signal when tid status change

倾然丶 夕夏残阳落幕 提交于 2021-02-08 11:19:33
问题 There is a way to look when pid/tid status change with waitpid but this is blocking function. I want to monitor all threads in specific pid and get signal when one of them change and print the tid. For now I open threads as count of threads in that process and each 1 make waitpid on 1 tid and after that blocking function finish I print that tid that changed. How can I get a signal that tid change so I can monitor all tid's in 1 thread. I didn't want to monitor all pid in system only specific

Sending SIGINT to forked exec process which runs script does not kill it

本小妞迷上赌 提交于 2021-02-08 09:19:14
问题 I'm writing shell application with C and encountered a problem that sending SIGINT to process running script won't stop it. Sending the same signal to a normal executable works just fine. Example: Bash script which just imitates long working script (work.sh): #! /bin/bash COUNTER=0 while true do ((COUNTER+=1)) echo "#${COUNTER} Working..." sleep 1 done C code: int main() { pid_t pid = fork(); if (pid == 0) { char* cmds[] = { "./work.sh", NULL }; if (execvp(cmds[0], cmds) == -1) { exit(1); } }

Sending SIGINT to forked exec process which runs script does not kill it

Deadly 提交于 2021-02-08 09:19:01
问题 I'm writing shell application with C and encountered a problem that sending SIGINT to process running script won't stop it. Sending the same signal to a normal executable works just fine. Example: Bash script which just imitates long working script (work.sh): #! /bin/bash COUNTER=0 while true do ((COUNTER+=1)) echo "#${COUNTER} Working..." sleep 1 done C code: int main() { pid_t pid = fork(); if (pid == 0) { char* cmds[] = { "./work.sh", NULL }; if (execvp(cmds[0], cmds) == -1) { exit(1); } }

Don't send SIGINT on CTRL+C to child processes but don't ignore the signal itself

那年仲夏 提交于 2021-02-08 03:44:30
问题 I'm trying to write a Task control program, very much like Supervisor. I run some programs from a config file and let them run in the background, while in the main process I read and execute other commands. Before fork() -ing, in the main process I call: sigaction(SIGINT, &the_handler, NULL); Where the_handler stores the reference of a simple print function. When CTRL+C is pressed, the child processes are interrupted as well (which I don't want). I could run: signal(SIGINT, SIG_IGN); after

Don't send SIGINT on CTRL+C to child processes but don't ignore the signal itself

不想你离开。 提交于 2021-02-08 03:44:01
问题 I'm trying to write a Task control program, very much like Supervisor. I run some programs from a config file and let them run in the background, while in the main process I read and execute other commands. Before fork() -ing, in the main process I call: sigaction(SIGINT, &the_handler, NULL); Where the_handler stores the reference of a simple print function. When CTRL+C is pressed, the child processes are interrupted as well (which I don't want). I could run: signal(SIGINT, SIG_IGN); after

What's the problem of pause() at all?

被刻印的时光 ゝ 提交于 2021-02-07 19:16:13
问题 According to this paragraph ,the following has problem: /* usr_interrupt is set by the signal handler. */ if (!usr_interrupt) pause (); /* Do work once the signal arrives. */ ... And should use sigsuspend instead. But I still don't see what the problem is with pause and how sigsuspend solves it, anyone can explain in more details? 回答1: Let's examine what happens when a signal arrives after you've checked usr_interrupt but before you call pause : main thread signal handler ----------- --------

What's the problem of pause() at all?

我的未来我决定 提交于 2021-02-07 19:14:56
问题 According to this paragraph ,the following has problem: /* usr_interrupt is set by the signal handler. */ if (!usr_interrupt) pause (); /* Do work once the signal arrives. */ ... And should use sigsuspend instead. But I still don't see what the problem is with pause and how sigsuspend solves it, anyone can explain in more details? 回答1: Let's examine what happens when a signal arrives after you've checked usr_interrupt but before you call pause : main thread signal handler ----------- --------

What's the problem of pause() at all?

社会主义新天地 提交于 2021-02-07 19:14:12
问题 According to this paragraph ,the following has problem: /* usr_interrupt is set by the signal handler. */ if (!usr_interrupt) pause (); /* Do work once the signal arrives. */ ... And should use sigsuspend instead. But I still don't see what the problem is with pause and how sigsuspend solves it, anyone can explain in more details? 回答1: Let's examine what happens when a signal arrives after you've checked usr_interrupt but before you call pause : main thread signal handler ----------- --------

Daemonization and SIGHUP

旧城冷巷雨未停 提交于 2021-02-07 19:14:06
问题 http://www.masterraghu.com/subjects/np/introduction/unix_network_programming_v1.3/ch13lev1sec4.html (excerpt from Richard Steven's UNIX Network Programming Vol. 1) includes Signal(SIGHUP, SIG_IGN); as part of the daemon_init function because: ..."We must ignore SIGHUP because when the session leader terminates (the first child), all processes in the session (our second child) receive the SIGHUP signal." The core of the function is: int i; pid_t pid; if ( (pid = Fork()) < 0) return (-1); else