/bin/sh exec & pipe

Hi,
I would like to start a program with logging from an sh script. I created two test scripts:

starter.sh:
Code:
#!/bin/sh
exec ./producer.sh | logger
producer.sh:
Code:
#!/bin/sh
while :
do
        echo "hello"
        sleep 5
done

My problem is that when I start starter.sh it's process remains in the system and additional processes for producer.sh and logger are created.

If I do
Code:
exec ./producer.sh >> /var/log/messages
instead of
Code:
exec ./producer.sh | logger
then it is OK, I cannot see a process for starter.sh.

The original version should work with the pipe to logger. How could I make it work?

Thanks for any help!
 
From sh(1):
exec [command [arg ...]]
Unless command is omitted, the shell process is replaced with the specified program (which must be a real program, not a shell built-in command or function). Any redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes.

Just remove the exec from your starter script.
 
SirDice said:
From sh(1):


Just remove the exec from your starter script.

I was not clear enough: I do not want starter.sh to be in the system once it started "./producer.sh | logger".
It behaves the same from this point of view with or without exec: ps shows a process for starter.sh (and I do not want it to be there). With no exec it is the expected behaviour I guess.
I would like to find a solution to start "./producer.sh | logger" and the starting scrip should not be in the system after that.
 
Piping requires parent process to be running to stream the I/O via pipe. In this case the parent is starter.sh.
 
expl said:
Piping requires parent process to be running to stream the I/O via pipe. In this case the parent is starter.sh.
So there is no way to avoid this "feature"... Thanks!
 
Back
Top