On 2014-07-04, Smita Gaikwad <
smitaga...@gmail.com> wrote:
> I have one program parent.c as follows:
The topic of signal semantics of C programs on Unix is much better suited to
the comp.unix.programmer newsgroup than comp.unix.admin.
> And executed binary parent. If i send signal SIGINT(ctrl+c) to parent, that
> signal is propagated to child process and it terminates.
That is correct. The TTY-generated SIGINT goes to every process in the
foreground process group, regardless of how they are related together by
parent/child relationships.
> I don't want to
> propagate signal to child process what can i do. Please note in my project i
> don't have access to child.c i can't modify it and there could be many such
> binary which i need to execute through popen this is just sample program.
There are bunch of things you can try.
1. Take advantage of the fact that, in the exec family of system calls,
signals which are set to the SIG_IGN disposition (ignored)
stay in the SIG_IGN disposition in the new image.
This means that you can fork the child process. Then in the child
process set SIGINT to SIG_IGN, and then exec the child executable.
2. You can remove the child process from the process group of the
tty session before execing the child executable.
If that program is to keep running, then it logically isn't part
of the tty session any more. It should close the tty, and create
its own session, like a daemon.
Approach 1 will only work if the child process does not manipulate its signals.
For example if the child happens to run code which iterates over signals and
sets everything to SIG_DFL, then that will defeat the approach.