TL;DR
This is definitely NOT a bug with startpar
, which is doing exactly what it promises to in the first place.
The output of each script is buffered and written when the script exits, so output lines of different scripts won't mix. You can modify this behaviour by setting a timeout.
Code details
Within the run()
function in startpar.c
,
Line 422: Obtain a handle to the master pseudoterminal (
/dev/ptmx
in this case)p->fd = getpt();
Line 429: Obtain the path of the corresponding slave pseudoterminal
else if ((m = ptsname(p->fd)) == 0 || grantpt(p->fd) || unlockpt(p->fd))
Line 438: Fork a child process
if ((p->pid = fork()) == (pid_t)-1)
Line 475: Invalidate default
stdout
TEMP_FAILURE_RETRY(close(1));
Line 476: Obtain a handle to slave pseudoterminal. Now, this is
1
, i.e. thestdout
of child now redirects to the slave pseudoterminal (and is received by the master pseudoterminal node).if (open(m, O_RDWR) != 1)
Line 481: Also capture
stderr
by duplicating it with the salve pseudoterminal fd.TEMP_FAILURE_RETRY(dup2(1, 2));
Line 561: After some book-keeping stuff, launch the executable of interest(as the child process)
execlp(p->name, p->arg0, (char *)0);
The parent process can then later on capture all the output/error logs of this newly launched process by reading the buffered master pseudoterminal and log it to the actual stdout (i.e.
/dev/console
in this case).
How to prevent a dangling startpar -f ...
process on your system?
Method 1: Define the executable to be launched as interactive.
Explicitly marking a executable interactive tells startpar
to skip the psedoterminal master/slave trickery to buffer the terminal I/O as any output of the launched interactive executable needs to be displayed on screen immediately and not buffered.
This modifies the flow of execution in several places. Mainly at Line 1171, where startpar
does NOT call the run()
function for an interactive executable.
This has been tested and described here.
Method 2: Discard stdout
and stderr
of the executable to be launched.
Using the construct ">/dev/null 2>&1 &"
discard stdout
/stderr
of the executable to be launched. If they are both explicitly set to NULL i.e. startpar does NOT buffer them indefinitely as it usually does otherwise.
Method 3: Set an explicit timeout for startpar
Either configure timo
in startpar.c
The timeout set with the
-t
option is used as buffer timeout. If the output buffer of a script is not empty and the last output was timeout seconds ago, startpar will flush the buffer.
or gtimo
in startpar.c
The
-T
option timeout works more globally. If no output is printed for more than global_timeout seconds, startpar will flush the buffer of the script with the oldest output. Afterwards it will only print output of this script until it is finished.