Questions tagged [sigaction]

The sigaction() system call is used to change the action taken by a process on receipt of a specific signal.

The sigaction() function allows the calling process to examine and/or specify the action to be associated with a specific signal. In computing, sigaction is a function API defined by POSIX to give the programmer access to what should be a program's behavior when receiving specific OS

106 questions
11
votes
2 answers

Sigaction and porting Linux code to Windows

I am trying to port caffe (developed for Linux) source code to Windows environment. The problem is at sigaction structure at signal_handler.cpp and signal_handler.h. The source codes are shown below. My query is which library or code replacement can…
batuman
  • 7,066
  • 26
  • 107
  • 229
8
votes
2 answers

Why does alarm() cause fgets() to stop waiting?

I am playing around with signals in C. My main function basically asks for some input using fgets(name, 30, stdin), and then sits there and waits. I set an alarm with alarm(3), and I reassigned SIGALRM to call a function myalarm that simply calls…
Aaron Parisi
  • 464
  • 7
  • 15
5
votes
1 answer

Why bash background task ignores SIGINT?

I noticed that sleep can't be killed by SIGINT when spawned by: (sleep 1000 &) I wonder why is so. All of the following are killed by SIGINT: sleep 1000 sleep 1000 & (sleep 1000) ( ( (sleep 1000) ) ) ( ( (sleep 1000)& ) ) so I figure it must have…
yjay
  • 942
  • 4
  • 11
5
votes
2 answers

macOS `sigaction()` handler with `SA_SIGINFO` does not include `si_pid`

I'm trying to write a signal handler which needs to know the pid of the process that sends the signal. I'm having no luck with getting anything useful from the siginfo_t passed into my handler on macOS 10.14 with Xcode 10. I've reduced my code to…
Brad Allred
  • 7,323
  • 1
  • 30
  • 49
5
votes
1 answer

How to call sigaction from C++

I know how to use it in C (with signal.h), but the library is provided in C++ and I want to know if it includes sigaction? I tried running it but it said not found. I was wondering if I did something wrong? #include #include…
Aiden Woodruff
  • 341
  • 3
  • 9
5
votes
1 answer

How can sigaction be both struct and function?

I noticed that sigaction is defined as both a struct and a function(http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html): int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict); And an example…
boyang
  • 667
  • 1
  • 8
  • 22
4
votes
3 answers

Do I have to use a signal handler for a Posix timer?

I want to start a timer and have a function called when it expires. Googling finds lots of examples, including the example in the manual, all of which use sigaction() to set a signal handler. However, @Patryk says in this question that we can…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
4
votes
1 answer

sigaction's signal handler not called in child process

I've a program, which installs a signal handler for SIGSEGV. In signal handler ( I try to catch crash ) I restart my application. But when my application is resurrected it doesn't handle SIGSEGV anymore. Here's an example: #include…
Michał Walenciak
  • 4,257
  • 4
  • 33
  • 61
4
votes
5 answers

sigaction and ignoring a signal with c in linux environment

I am new to this type of programming, so sorry if my question is trivial. What I am trying to do is to cause a segmentation fault in my program and instead of exiting the program, I want to handle the signal and continue execution after segmentation…
Saik
  • 993
  • 1
  • 16
  • 40
4
votes
1 answer

Multiple signals arriving at handler

I have a main process that has forked some kid processes. Each kid does something and blocks itself. By blocking itself every child sends a SICHLD signal to the parent process. I also have declared a sigaction action, in the main process code, in…
pirox22
  • 892
  • 1
  • 14
  • 30
4
votes
1 answer

OS X sigaction incorrectly setting sa_mask

On a macbook (OSX 10.9.5 (13F34)) the following simple program: #include #include static void nop(int unused) { } int main(void) { struct sigaction sa, osa; sigset_t mask; sigemptyset(&sa.sa_mask); …
Dave
  • 10,964
  • 3
  • 32
  • 54
3
votes
1 answer

Why is context in sigaction handler a void pointer?

In sigaction(2) man page: The siginfo_t argument to a SA_SIGINFO handler When the SA_SIGINFO flag is specified in act.sa_flags, the signal handler address is passed via the act.sa_sigaction field. This han‐ dler takes three arguments, as…
Adam Thompson
  • 3,278
  • 3
  • 22
  • 37
2
votes
1 answer

Server receiving and showing string from client using signals SIGUSR1 and SIGUSR2 can't handle with big amount of symbols

I had a task from school in which I need to write a client that will send string using signals (only SIGUSR1 as 1 or SIGUSR2 as 0) to server, which then should display this string. The problem is that server can normally handle only a little amount…
Makar
  • 21
  • 4
2
votes
1 answer

sigaction is catching signal only once

Consider the following code: #include #include void catch () { printf("hi\n"); } int main() { struct sigaction act; act.sa_handler = catch; sigaction(SIGINT, &act, NULL); …
asha rani
  • 41
  • 6
2
votes
1 answer

Restarting process when receiving a signal with sigaction

I'm trying to make my process restart when it receives SIGUSR1. Since SIGINT is easier to test, I'm using it instead. Here's the code: #include #include #include void sig_handler(int signo){ if (signo == SIGINT){ …
leosole
  • 331
  • 4
  • 13
1
2 3 4 5 6 7 8