Search code examples
c++forkexecv

After fork, execv communicates with the parent process when executing the target program


I know that the signal handler cannot be inherited when call execv in the child process of fork, so I wonder if the execv process can be piped to communicate with the parent process. As far as I know, pipe communication requires parenthood or a common ancestor. But I don't know if the pipe mechanism still works in execv.

Here's what I'm trying to do: Contains an breakpoint signal in the target program execv will execute.Is it possible that I want to be able to tell the parent process this message when a breakpoint is triggered? What can I do with it?


Solution

  • I'm not sure if I fully understand your question, but I think you're trying to set up signal handlers in the child process, then call execv, with your signals handlers still ready ?

    You can't. Upon calling execv, the calling process is replaced by the executed program. Your file descriptor manipulation are preserved by default, so you can pipe stdout or stderr to wherever you want(file, parent stdin, ...) but everything else is wiped.

    execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded. The program invoked inherits the calling process's PID, and any open file descriptors that are not set to close on exec. Signals pending on the calling process are cleared. Any signals set to be caught by the calling process are reset to their default behaviour. The SIGCHLD signal (when set to SIG_IGN) may or may not be reset to SIG_DFL.

    EDIT: So read the history of your question (why did you edited it ? I was much clearer, imo). But you should take a look at the ptrace syscall (on linux, don't know the equivalent on windows)