signals

compile errors using signal.h in Linux [duplicate]

给你一囗甜甜゛ 提交于 2019-12-04 23:15:49
This question already has an answer here: struct sigaction incomplete error 2 answers I'm writing a shell program that must handle signals. My relevant signal handling related code is as follows: #include <signal.h> ... #include <sys/types.h> ... void installSigactions( int, struct sigaction* ); void handler_function( int signal_id ); ... /*define signal table*/ struct sigaction signal_action; /*insert handler function*/ signal_action.sa_handler = handler_function; /*init the flags field*/ signal_action.sa_flags = 0; /*are no masked interrupts*/ sigemptyset( &signal_action.sa_mask ); /*install

Get pid of the process which has triggered some signal

我是研究僧i 提交于 2019-12-04 23:10:56
问题 Is it possible to find out the process id of the process which has caused some signal. In my scenario, I have multiple children of a process running, and I want to know which one of them sent the signal. 回答1: It is (finally!) very simple with python 3. The following is tested with python 3.3.3: #! /usr/bin/python3 import signal import time, os def callme(num, frame): pass # register the callback: signal.signal(signal.SIGUSR1, callme) print("py: Hi, I'm %d, talk to me with 'kill -SIGUSR1 %d'"

I want to receive data CONTINUOUSLY from a COM port & simultaneously want to write to file

余生长醉 提交于 2019-12-04 22:29:10
I want to read serial COM port and to write the data to a file in LINUX. Actually I'm sending data from hyperterminal from other PC. The problem is without while loop I can write only one line. But with while(1) loop I can't write anything to file. Or else I have to send BIG file, then application exits/terminates and writes to the file. My application should write the data (it may 2 lines or any thing); after that it has to wait for next data. So please help me out..... Here is my Code ========================================= #include <termios.h> #include <stdio.h> #include <unistd.h>

how to send signal from one program to another?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 22:18:49
问题 i am using message queue as an ipc between 2 programs. Now i want to send data from one program to another using message queue and then intimate it through a signal SIGINT. I dont know how to send a signal from one program to another . Can anybody pls provide a sample code if they have the solution. 回答1: #include <sys/types.h> #include <signal.h> int kill(pid_t pid, int sig); 回答2: Signal in linux can be send using kill system call just check this link for documentation of kill system call and

Why I am not getting signal SIGKILL on kill -9 command in bash?

亡梦爱人 提交于 2019-12-04 21:57:06
问题 In bash script I handle different signal as follows: #!/bin/bash sighdl () { echo "signal caught" #do something exit 0 } trap sighdl SIGKILL SIGINT SIGTERM Above code handle signal properly for following activity: Ctrl + C kill pid pkill scriptname For kill -9 pid it does not call sighdl . As per my understanding (if I am not wrong) kill -9 sends the SIGKILL signal. Any idea? 回答1: You cannot do that. Yes 9 is SIGKILL and Unix system by design doesn't allow any script/program to trap SIGKILL

Propagating Signal (SIGINT) to C++11 threads

我只是一个虾纸丫 提交于 2019-12-04 21:02:14
问题 I am trying to terminate correctly my multi-threaded C++11 application upon receiving SIGINT signal ( ^C it is), but for some reason it does not propagate to child threads, though main thread responds to it well. For instnce (as in code sample below), if we have a some blocking function inside of thread (like sleep() ), it will take out all ^C control from you if you installed any SIGNT hooks using, say, sigaction() function. Is there any way to fix- or work-around such behavior? Is there a

Is it possible to make an arbitrary program ignore signals?

孤人 提交于 2019-12-04 19:45:48
Specifically on Mac OS X, is it possible to make a program ignore SIGTERM via DYLD_INSERT_LIBRARIES, in a way which works for any or most programs? I tried compiling and inserting this: #include<stdio.h> #include<signal.h> #include<unistd.h> void sig_handler(int signo) { if (signo == SIGTERM) printf("received SIGTERM\n"); } int main(void) { signal(SIGTERM, sig_handler); return 0; } However, DYLD_INSERT_LIBRARIES=libignore.dylib sleep 60 was able to be kill -15'd without issue. You can create an executable that sets the action for SIGTERM to SIG_IGN and then execvp() the program you would like

Exit code of traps in Bash

血红的双手。 提交于 2019-12-04 19:34:35
问题 This is myscript.sh : #!/bin/bash function mytrap { echo "Trapped!" } trap mytrap EXIT exit 3 And when I run it: > ./myscript.sh echo $? 3 Why is the exit code of the script the exit code with the trap the same as without it? Usually, a function returns implicitly the exit code of the last command executed. In this case: echo returns 0 I would expect mytrap to return 0 Since mytrap is the last function executed, the script should return 0 Why is this not the case? Where is my thinking wrong?

Is the data in siginfo trustworthy?

梦想的初衷 提交于 2019-12-04 19:28:23
问题 I've found that on Linux, by making my own call to the rt_sigqueue syscall, I can put whatever I like in the si_uid and si_pid fields and the call succeeds and happily delivers the incorrect values. Naturally the uid restrictions on sending signals provide some protection against this kind of spoofing, but I'm worried it may be dangerous to rely on this information. Is there any good documentation on the topic I could read? Why does Linux allow the obviously-incorrect behavior of letting the

send signal between scripts (bash)

岁酱吖の 提交于 2019-12-04 19:07:46
I've a little problem, probably it's a stupid question, but I started learning bash about a week ago... I have 2 script, a.sh and b.sh. I need to make both running constantly. b.sh should waits for a signal from a.sh (I'm trying to explain: a.sh and b.sh run --> a.sh sends a signal to b.sh -> b.sh traps signal, does something --> a.sh does something else and then sends another signal --> b.sh traps signal, does something --> etc.) This is what I've tried: a.sh: #!/bin/bash ./b.sh &; bpid=$!; # do something..... while true do #do something.... if [ condition ] then kill -SIGUSR1 $bpid; fi done