Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
#!/bin/ksh
# start_service: start the service
my_server_executable 2>&1 | my_pipe_following_shell_script &
exit 0

After I run the above start_service script from command line, it is observed using ps command that the bash process running my_pipe_following_shell_script is parent of my_server_executable, whereas I would expect, and need, the latter to be owned by PID 1 (init) instead.

I am looking for an explanation as to why this has happened and how I can avoid this.

Also how does one go about debugging/examining what goes on behind-the-scenes? Running start_service with strace isn't very helpful. The only interesting line I could find in its output is:

clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7f05708) = 30431

where 30431 is PID of my_pipe_following_shell_script.


Linux 2.6.18-308.16.1.el5PAE

ksh Version sh (AT&T Research) 93t+ 2010-02-02

GNU bash, version 3.2.25(1)-release (i686-redhat-linux-gnu)

share|improve this question
add comment

1 Answer 1

Your shell — ksh in this case — is the parent of the processes on both sides of the pipe, because it started them both. All it does between starting one and the other is set up the pipe between them, so that the stdout of the first goes to the stdin of the second.

If you need the two-process agglomeration to be run in the background, this will do it:

( my_server_executable 2>&1 | my_pipe_following_shell_script ) &

That starts the two programs — connected via a pipe — within a subshell, which is put into the background via &.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.