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
0
votes
0 answers

What should I put in a signal handler to make it terminate all processes except the parent?

I'm making a basic shell in C and I want to catch Ctrl+C so that it doesn't kill my program, but instead kills all processes running under my program. I don't know what code to set put in my signal handler to get this effect. Furthermore, once I…
Alex
  • 394
  • 1
  • 4
  • 15
0
votes
0 answers

Why does sigaction invoke core dump

int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); If act is non-NULL, the new action for signal signum is installed from act. If oldact is non-NULL, the previous action is saved in oldact. This comes from…
Yves
  • 11,597
  • 17
  • 83
  • 180
0
votes
0 answers

Using sigaction, SIGKILL and an alarm handler to kill a forked process that takes longer than 3 seconds

I'm writing a C program that pipes the output of a first program into the input of a second program. The program needs to terminate with the use of sigaction and SIGKILL if either program takes longer than 3 seconds to reach termination. My program…
0
votes
1 answer

Use of .sa_sigaction and .sa_handler in same project(man page clarification)

While looking up the man pages for sigaction, I stumbled upon a confusing note in the Linux man pages: On some architectures a union is involved: do not assign to both sa_handler and sa_sigaction(sigaction man page). There are two possible ways…
J.Panek
  • 425
  • 5
  • 16
0
votes
1 answer

Sigaction declaration in functions

Is sigaction in Unix declared only once in main function, or should I declare it inside every function my main calls, so if a signal comes when the execution is not inside my main, the signal handler will invoke? So, do I have to declare sigaction…
Fra Papas
  • 17
  • 3
0
votes
1 answer

Problem stopping a child loop using sigaction and intercepting Ctrl*C

I'm trying to write a program that intercepts Ctrl^C using sigaction, and then terminates the child of a fork. Code: static void usrHandler(int sig, siginfo_t * si, void * ignore) { printf("Interrupt Worked"); } int main(int argc, char *…
sixstring
  • 31
  • 6
0
votes
1 answer

How to fix Signal Handler assignment

For Linux C programming, I have this handler and main method: void handler(int number, signinfo_t, void *ignore){ printf("Signaling %d\n", si->si_pid); } int main(){ struct sigaction sig; sig.sa_flags = SA_SIGINFO; …
user11157060
0
votes
3 answers

How do I use sigaction()? struct sigaction is not defined

I am doing simple sigaction example to practice C, but when I try to compile my code, it claims that struct sigaction doesn't exist [1]. When I checked out some old code I had produced I saw that I had added some POSIX string at the very top of the…
Donkey King
  • 87
  • 1
  • 8
0
votes
1 answer

SIGHUP signal handling to deamonize a command in Unix system programming

I am reading a book about Unix system programming. In the book there is a function to create a daemon process. Part of the code is not very clear to me, particularly the following: struct sigaction sa; .... /* *Become a session leader to lose…
roschach
  • 8,390
  • 14
  • 74
  • 124
0
votes
1 answer

SIGACTION Structure

I have built a function (based in a example) that allows me to ignore the signal SIGINT. That function counts the times that the user press CONTROL + C (the interruption SIGINT). The function is the following one #include #include…
João
  • 13
  • 1
  • 8
0
votes
1 answer

Error using sigaction multiple times

I'm trying to call a function everytime my child process dies. This is done by catching the SIGCHLD sent by execve(). My problem here is that my handler function is not always called a second time. Sometimes it is though so I'm a bit confused. My…
João Valente
  • 185
  • 1
  • 1
  • 9
0
votes
0 answers

sigaction for SIGINT, SA_RESETHAND

Is there a way to handle SIGINT only 2 times and return it to default using SA_RESETHAND? We must use sigaction, and make our handler reinstall by itself 2 times and then install flags to resethand. But there's a question: how to reinstall my…
duude12
  • 1
  • 3
0
votes
0 answers

C - using dup to redirect stdout to execl(binary file)'s input

I need help with the following program, It's supposed to fork() two childs, child1 should send two random numbers, in a string separated by space, to child2 trough pipe, wait 1 sec and do it again until it receives SIGUSR1 from the parent(parent…
Petr Kroupa
  • 53
  • 3
  • 8
0
votes
1 answer

Minishell background

I am doing a minishell project for college, and I don't know how to execute commands in background. The one thing i know is that i have to use waitpid() and sigaction(), but i don't know how. If somebody would give me a hand with this i will be…
0
votes
0 answers

Signal handling in C with sigaction

I'm trying to implement a simple unix shell in C. However, my background process feature is not working well. When I run the shell and give a background command, it gives the output like the following: > sleep 4 & > [10612]retval: 0 >…
Enes Altuncu
  • 449
  • 2
  • 7
  • 14