[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: where does command output go



On Sun, Nov 9, 2025 at 6:25 AM <fxkl47BF@protonmail.com> wrote:
> i execute
> some_long_running_command | mail billy_bob@localhost
> where is the output of the command stored while it is running before it's mailed
With | the shell handles opening pipe between the two processes, in your example
some_long_running_command
and
mail billy_bob@localhost
The kernel then handles that - there's a certain amount of buffer size
the kernel allocates
to the pipe, e.g. 64KiB.  That's in RAM (or at least virtual memory).
That size may also possibly be adjusted.
See also, e.g.: pipe(2), pipe2(2), pipesz(1), etc.
The mail program in such mode, taking stdin for body of mail to be sent,
collects and stores the stdin data it receives, generally to a file somewhere
under /var (per FHS), though precise location may depend upon the particular
mail program one may be using.
And, at my particular Debian (12.12 amd64) where I peeked at that,
and what I have installed there,
for mail program I have bsd-mailx.
Having a look with strace(1), that mail program first stored the data
(message body) in
/tmp/mail.RsXXXX7I9ipp
location of which may possibly be altered by configuration for the program
and/or TMPDIR in the environment.  Once it had processed all the input data
and successfully written it there,
it then opened and wrote another file:
/tmp/mail.RsXXXXUjcCyg
and wrote email headers and message body to that file,
It then manipulates file descriptor(s) so that becomes fd 0 (stdin)
and then it execve(2)ed /usr/sbin/sendmail
For brevity, I omitted many details, e.g. options, arguments, various
unlinking and
closing of files, etc.
And, your mileage may/will vary, depending exactly which programs and
versions you have
installed for these various bits of functionality (e.g. mail, MTA, etc.),
and configurations and/or environmental settings thereof.

Anyway, in general, pipe buffers a bit, mail program will buffer to a file,
then typically hand off to MTA.  And there may be additional steps between
(like adding mail headers - not sure why it didn't do that first, as
it didn't include time, length, or other variable headers - though
perhaps that might've been different depending upon what content it
was handed).  And (not covered), MTA will typically spool to file, and
then make
delivery attempt(s).


Reply to: