Confusion about stdout and stderr on the start-up terminal

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















I have an embedded Linux system with different programs running from start-up. Some of these programs write to stdout and stderr with printf().



When I first log into the system via SSH, I can see all of these messages appear on the terminal.



However , when I open another SSH session after this, of course the processes are still running but nothing is getting wrote to that terminal. This makes me confused about how stdout and stderr actually work. I thought they would write to all terminals open?










share|improve this question
























  • How exactly are the programs started?

    – ilkkachu
    Feb 14 at 19:16






  • 1





    Do you mean you log in, start the program(s) and can see the messages on the terminal. Then you log out and log in again and can't see them? That's to be expected. Redirect to a log file instead.

    – Kusalananda
    Feb 14 at 19:37











  • @Kusalananda In my case, actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. and then all the messages from the start-up scripts when the system starts. However if I then connect via another terminal on another computer using SSH over the LAN to the system, I do not see these debug messages flooding the screen, which I thought I would. Thanks

    – Engineer999
    Feb 15 at 7:11















0















I have an embedded Linux system with different programs running from start-up. Some of these programs write to stdout and stderr with printf().



When I first log into the system via SSH, I can see all of these messages appear on the terminal.



However , when I open another SSH session after this, of course the processes are still running but nothing is getting wrote to that terminal. This makes me confused about how stdout and stderr actually work. I thought they would write to all terminals open?










share|improve this question
























  • How exactly are the programs started?

    – ilkkachu
    Feb 14 at 19:16






  • 1





    Do you mean you log in, start the program(s) and can see the messages on the terminal. Then you log out and log in again and can't see them? That's to be expected. Redirect to a log file instead.

    – Kusalananda
    Feb 14 at 19:37











  • @Kusalananda In my case, actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. and then all the messages from the start-up scripts when the system starts. However if I then connect via another terminal on another computer using SSH over the LAN to the system, I do not see these debug messages flooding the screen, which I thought I would. Thanks

    – Engineer999
    Feb 15 at 7:11













0












0








0








I have an embedded Linux system with different programs running from start-up. Some of these programs write to stdout and stderr with printf().



When I first log into the system via SSH, I can see all of these messages appear on the terminal.



However , when I open another SSH session after this, of course the processes are still running but nothing is getting wrote to that terminal. This makes me confused about how stdout and stderr actually work. I thought they would write to all terminals open?










share|improve this question
















I have an embedded Linux system with different programs running from start-up. Some of these programs write to stdout and stderr with printf().



When I first log into the system via SSH, I can see all of these messages appear on the terminal.



However , when I open another SSH session after this, of course the processes are still running but nothing is getting wrote to that terminal. This makes me confused about how stdout and stderr actually work. I thought they would write to all terminals open?







linux ssh terminal stdout stderr






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 14 at 19:23









Rui F Ribeiro

41.4k1481140




41.4k1481140










asked Feb 14 at 19:14









Engineer999Engineer999

31319




31319












  • How exactly are the programs started?

    – ilkkachu
    Feb 14 at 19:16






  • 1





    Do you mean you log in, start the program(s) and can see the messages on the terminal. Then you log out and log in again and can't see them? That's to be expected. Redirect to a log file instead.

    – Kusalananda
    Feb 14 at 19:37











  • @Kusalananda In my case, actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. and then all the messages from the start-up scripts when the system starts. However if I then connect via another terminal on another computer using SSH over the LAN to the system, I do not see these debug messages flooding the screen, which I thought I would. Thanks

    – Engineer999
    Feb 15 at 7:11

















  • How exactly are the programs started?

    – ilkkachu
    Feb 14 at 19:16






  • 1





    Do you mean you log in, start the program(s) and can see the messages on the terminal. Then you log out and log in again and can't see them? That's to be expected. Redirect to a log file instead.

    – Kusalananda
    Feb 14 at 19:37











  • @Kusalananda In my case, actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. and then all the messages from the start-up scripts when the system starts. However if I then connect via another terminal on another computer using SSH over the LAN to the system, I do not see these debug messages flooding the screen, which I thought I would. Thanks

    – Engineer999
    Feb 15 at 7:11
















How exactly are the programs started?

– ilkkachu
Feb 14 at 19:16





How exactly are the programs started?

– ilkkachu
Feb 14 at 19:16




1




1





Do you mean you log in, start the program(s) and can see the messages on the terminal. Then you log out and log in again and can't see them? That's to be expected. Redirect to a log file instead.

– Kusalananda
Feb 14 at 19:37





Do you mean you log in, start the program(s) and can see the messages on the terminal. Then you log out and log in again and can't see them? That's to be expected. Redirect to a log file instead.

– Kusalananda
Feb 14 at 19:37













@Kusalananda In my case, actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. and then all the messages from the start-up scripts when the system starts. However if I then connect via another terminal on another computer using SSH over the LAN to the system, I do not see these debug messages flooding the screen, which I thought I would. Thanks

– Engineer999
Feb 15 at 7:11





@Kusalananda In my case, actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. and then all the messages from the start-up scripts when the system starts. However if I then connect via another terminal on another computer using SSH over the LAN to the system, I do not see these debug messages flooding the screen, which I thought I would. Thanks

– Engineer999
Feb 15 at 7:11










1 Answer
1






active

oldest

votes


















2














If you're using the first SSH login to connect to "a serial debug interface", as you mentioned in the comments, then your embedded device is simply using the serial port as a console device. That's a common solution on Linux systems with no video display device at all, and actually the way classic Unix computers worked by default.



On start-up, the boot messages are output on /dev/console, and some of the started programs don't fully detach from the terminal device they've started on, and keep sending messages to it.



Technically this would be "a failure to fully daemonize" on the application's part if the application messages are unneeded, or "a half-a**ed way to implement application logging" if the messages are useful and the sysadmin is expected to write start-up scripts to direct the messages to a log file or some other useful destination. Sadly, this is relatively common. Cluttering up the console device with application messages can make it difficult for the sysadmin to use the console to troubleshoot any problems that cause the network connection to fail.




(The part below this was written before the fact that a serial debug interface was involved in that first SSH session was mentioned...)



The standard input, output and error streams are normally connected to one terminal device only. The only obvious special case would be /dev/console, which should cause the output on all physical console devices... but that does not include pseudo-TTYs, and a SSH connection will always be using a pseudo-TTY (or no TTY at all), never a "real" TTY device.



If your "programs running from start-up" are really started up at boot time, and not at your first login, then this is an interesting puzzle.



If your embedded system uses legacy (BSD-style) pseudo-TTY devices, then I think I know how that might be possible. (In other words, does your system have pairs of device nodes named like /dev/pty?? and /tty?? respectively, or does it have the modern Unix98 style PTY devices like /dev/ptmx and /dev/pts/<number>?)



At start-up, whatever script or system is managing your boot process might assign the standard output & error of all your services to the first pseudo-TTY, where some form of boot log process would capture them for logging and then pass them on to the actual console TTY device. When the boot process is complete, the boot log process ends and releases the pseudo-TTY master side. But some of your start-up programs might not be releasing their side of the pseudo-TTY, and keep sending output to it.



When your first SSH session is established, the sshd daemon gets the first unallocated pseudo-TTY master device to be used for the connection... but with the BSD-style pseudo-TTY devices, it will be the same device node that was used in the boot logging. As a result, the first SSH session will get a pseudo-TTY device that will already have the start-up programs attached to the slave side of it, and so the output of those programs will appear in the SSH session. Other SSH sessions will get a "clean" pseudo-TTY device, and so the problem will not occur with them.



With modern Unix98-style pseudo-TTY devices, each new user of PTY devices will get a guaranteed-unique PTY device pair, so this kind of thing could only happen with BSD-style PTY devices.






share|improve this answer

























  • Ok thanks. It's interesting

    – Engineer999
    Feb 15 at 7:06











  • Actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. on boot-up and then all the messages from the start-up scripts when the system starts. The scripts continue to flood this terminal window as long as the system is running. However if I then connect via a different terminal on another computer using SSH over the LAN to the system, I do not see any of these debug messages flooding the screen. I'm interested to know as to why this is. Perhaps my understanding of stdout and stderr etc. is not clear

    – Engineer999
    Feb 15 at 7:12











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f500688%2fconfusion-about-stdout-and-stderr-on-the-start-up-terminal%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














If you're using the first SSH login to connect to "a serial debug interface", as you mentioned in the comments, then your embedded device is simply using the serial port as a console device. That's a common solution on Linux systems with no video display device at all, and actually the way classic Unix computers worked by default.



On start-up, the boot messages are output on /dev/console, and some of the started programs don't fully detach from the terminal device they've started on, and keep sending messages to it.



Technically this would be "a failure to fully daemonize" on the application's part if the application messages are unneeded, or "a half-a**ed way to implement application logging" if the messages are useful and the sysadmin is expected to write start-up scripts to direct the messages to a log file or some other useful destination. Sadly, this is relatively common. Cluttering up the console device with application messages can make it difficult for the sysadmin to use the console to troubleshoot any problems that cause the network connection to fail.




(The part below this was written before the fact that a serial debug interface was involved in that first SSH session was mentioned...)



The standard input, output and error streams are normally connected to one terminal device only. The only obvious special case would be /dev/console, which should cause the output on all physical console devices... but that does not include pseudo-TTYs, and a SSH connection will always be using a pseudo-TTY (or no TTY at all), never a "real" TTY device.



If your "programs running from start-up" are really started up at boot time, and not at your first login, then this is an interesting puzzle.



If your embedded system uses legacy (BSD-style) pseudo-TTY devices, then I think I know how that might be possible. (In other words, does your system have pairs of device nodes named like /dev/pty?? and /tty?? respectively, or does it have the modern Unix98 style PTY devices like /dev/ptmx and /dev/pts/<number>?)



At start-up, whatever script or system is managing your boot process might assign the standard output & error of all your services to the first pseudo-TTY, where some form of boot log process would capture them for logging and then pass them on to the actual console TTY device. When the boot process is complete, the boot log process ends and releases the pseudo-TTY master side. But some of your start-up programs might not be releasing their side of the pseudo-TTY, and keep sending output to it.



When your first SSH session is established, the sshd daemon gets the first unallocated pseudo-TTY master device to be used for the connection... but with the BSD-style pseudo-TTY devices, it will be the same device node that was used in the boot logging. As a result, the first SSH session will get a pseudo-TTY device that will already have the start-up programs attached to the slave side of it, and so the output of those programs will appear in the SSH session. Other SSH sessions will get a "clean" pseudo-TTY device, and so the problem will not occur with them.



With modern Unix98-style pseudo-TTY devices, each new user of PTY devices will get a guaranteed-unique PTY device pair, so this kind of thing could only happen with BSD-style PTY devices.






share|improve this answer

























  • Ok thanks. It's interesting

    – Engineer999
    Feb 15 at 7:06











  • Actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. on boot-up and then all the messages from the start-up scripts when the system starts. The scripts continue to flood this terminal window as long as the system is running. However if I then connect via a different terminal on another computer using SSH over the LAN to the system, I do not see any of these debug messages flooding the screen. I'm interested to know as to why this is. Perhaps my understanding of stdout and stderr etc. is not clear

    – Engineer999
    Feb 15 at 7:12
















2














If you're using the first SSH login to connect to "a serial debug interface", as you mentioned in the comments, then your embedded device is simply using the serial port as a console device. That's a common solution on Linux systems with no video display device at all, and actually the way classic Unix computers worked by default.



On start-up, the boot messages are output on /dev/console, and some of the started programs don't fully detach from the terminal device they've started on, and keep sending messages to it.



Technically this would be "a failure to fully daemonize" on the application's part if the application messages are unneeded, or "a half-a**ed way to implement application logging" if the messages are useful and the sysadmin is expected to write start-up scripts to direct the messages to a log file or some other useful destination. Sadly, this is relatively common. Cluttering up the console device with application messages can make it difficult for the sysadmin to use the console to troubleshoot any problems that cause the network connection to fail.




(The part below this was written before the fact that a serial debug interface was involved in that first SSH session was mentioned...)



The standard input, output and error streams are normally connected to one terminal device only. The only obvious special case would be /dev/console, which should cause the output on all physical console devices... but that does not include pseudo-TTYs, and a SSH connection will always be using a pseudo-TTY (or no TTY at all), never a "real" TTY device.



If your "programs running from start-up" are really started up at boot time, and not at your first login, then this is an interesting puzzle.



If your embedded system uses legacy (BSD-style) pseudo-TTY devices, then I think I know how that might be possible. (In other words, does your system have pairs of device nodes named like /dev/pty?? and /tty?? respectively, or does it have the modern Unix98 style PTY devices like /dev/ptmx and /dev/pts/<number>?)



At start-up, whatever script or system is managing your boot process might assign the standard output & error of all your services to the first pseudo-TTY, where some form of boot log process would capture them for logging and then pass them on to the actual console TTY device. When the boot process is complete, the boot log process ends and releases the pseudo-TTY master side. But some of your start-up programs might not be releasing their side of the pseudo-TTY, and keep sending output to it.



When your first SSH session is established, the sshd daemon gets the first unallocated pseudo-TTY master device to be used for the connection... but with the BSD-style pseudo-TTY devices, it will be the same device node that was used in the boot logging. As a result, the first SSH session will get a pseudo-TTY device that will already have the start-up programs attached to the slave side of it, and so the output of those programs will appear in the SSH session. Other SSH sessions will get a "clean" pseudo-TTY device, and so the problem will not occur with them.



With modern Unix98-style pseudo-TTY devices, each new user of PTY devices will get a guaranteed-unique PTY device pair, so this kind of thing could only happen with BSD-style PTY devices.






share|improve this answer

























  • Ok thanks. It's interesting

    – Engineer999
    Feb 15 at 7:06











  • Actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. on boot-up and then all the messages from the start-up scripts when the system starts. The scripts continue to flood this terminal window as long as the system is running. However if I then connect via a different terminal on another computer using SSH over the LAN to the system, I do not see any of these debug messages flooding the screen. I'm interested to know as to why this is. Perhaps my understanding of stdout and stderr etc. is not clear

    – Engineer999
    Feb 15 at 7:12














2












2








2







If you're using the first SSH login to connect to "a serial debug interface", as you mentioned in the comments, then your embedded device is simply using the serial port as a console device. That's a common solution on Linux systems with no video display device at all, and actually the way classic Unix computers worked by default.



On start-up, the boot messages are output on /dev/console, and some of the started programs don't fully detach from the terminal device they've started on, and keep sending messages to it.



Technically this would be "a failure to fully daemonize" on the application's part if the application messages are unneeded, or "a half-a**ed way to implement application logging" if the messages are useful and the sysadmin is expected to write start-up scripts to direct the messages to a log file or some other useful destination. Sadly, this is relatively common. Cluttering up the console device with application messages can make it difficult for the sysadmin to use the console to troubleshoot any problems that cause the network connection to fail.




(The part below this was written before the fact that a serial debug interface was involved in that first SSH session was mentioned...)



The standard input, output and error streams are normally connected to one terminal device only. The only obvious special case would be /dev/console, which should cause the output on all physical console devices... but that does not include pseudo-TTYs, and a SSH connection will always be using a pseudo-TTY (or no TTY at all), never a "real" TTY device.



If your "programs running from start-up" are really started up at boot time, and not at your first login, then this is an interesting puzzle.



If your embedded system uses legacy (BSD-style) pseudo-TTY devices, then I think I know how that might be possible. (In other words, does your system have pairs of device nodes named like /dev/pty?? and /tty?? respectively, or does it have the modern Unix98 style PTY devices like /dev/ptmx and /dev/pts/<number>?)



At start-up, whatever script or system is managing your boot process might assign the standard output & error of all your services to the first pseudo-TTY, where some form of boot log process would capture them for logging and then pass them on to the actual console TTY device. When the boot process is complete, the boot log process ends and releases the pseudo-TTY master side. But some of your start-up programs might not be releasing their side of the pseudo-TTY, and keep sending output to it.



When your first SSH session is established, the sshd daemon gets the first unallocated pseudo-TTY master device to be used for the connection... but with the BSD-style pseudo-TTY devices, it will be the same device node that was used in the boot logging. As a result, the first SSH session will get a pseudo-TTY device that will already have the start-up programs attached to the slave side of it, and so the output of those programs will appear in the SSH session. Other SSH sessions will get a "clean" pseudo-TTY device, and so the problem will not occur with them.



With modern Unix98-style pseudo-TTY devices, each new user of PTY devices will get a guaranteed-unique PTY device pair, so this kind of thing could only happen with BSD-style PTY devices.






share|improve this answer















If you're using the first SSH login to connect to "a serial debug interface", as you mentioned in the comments, then your embedded device is simply using the serial port as a console device. That's a common solution on Linux systems with no video display device at all, and actually the way classic Unix computers worked by default.



On start-up, the boot messages are output on /dev/console, and some of the started programs don't fully detach from the terminal device they've started on, and keep sending messages to it.



Technically this would be "a failure to fully daemonize" on the application's part if the application messages are unneeded, or "a half-a**ed way to implement application logging" if the messages are useful and the sysadmin is expected to write start-up scripts to direct the messages to a log file or some other useful destination. Sadly, this is relatively common. Cluttering up the console device with application messages can make it difficult for the sysadmin to use the console to troubleshoot any problems that cause the network connection to fail.




(The part below this was written before the fact that a serial debug interface was involved in that first SSH session was mentioned...)



The standard input, output and error streams are normally connected to one terminal device only. The only obvious special case would be /dev/console, which should cause the output on all physical console devices... but that does not include pseudo-TTYs, and a SSH connection will always be using a pseudo-TTY (or no TTY at all), never a "real" TTY device.



If your "programs running from start-up" are really started up at boot time, and not at your first login, then this is an interesting puzzle.



If your embedded system uses legacy (BSD-style) pseudo-TTY devices, then I think I know how that might be possible. (In other words, does your system have pairs of device nodes named like /dev/pty?? and /tty?? respectively, or does it have the modern Unix98 style PTY devices like /dev/ptmx and /dev/pts/<number>?)



At start-up, whatever script or system is managing your boot process might assign the standard output & error of all your services to the first pseudo-TTY, where some form of boot log process would capture them for logging and then pass them on to the actual console TTY device. When the boot process is complete, the boot log process ends and releases the pseudo-TTY master side. But some of your start-up programs might not be releasing their side of the pseudo-TTY, and keep sending output to it.



When your first SSH session is established, the sshd daemon gets the first unallocated pseudo-TTY master device to be used for the connection... but with the BSD-style pseudo-TTY devices, it will be the same device node that was used in the boot logging. As a result, the first SSH session will get a pseudo-TTY device that will already have the start-up programs attached to the slave side of it, and so the output of those programs will appear in the SSH session. Other SSH sessions will get a "clean" pseudo-TTY device, and so the problem will not occur with them.



With modern Unix98-style pseudo-TTY devices, each new user of PTY devices will get a guaranteed-unique PTY device pair, so this kind of thing could only happen with BSD-style PTY devices.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 15 at 7:59

























answered Feb 15 at 1:20









telcoMtelcoM

18.9k12347




18.9k12347












  • Ok thanks. It's interesting

    – Engineer999
    Feb 15 at 7:06











  • Actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. on boot-up and then all the messages from the start-up scripts when the system starts. The scripts continue to flood this terminal window as long as the system is running. However if I then connect via a different terminal on another computer using SSH over the LAN to the system, I do not see any of these debug messages flooding the screen. I'm interested to know as to why this is. Perhaps my understanding of stdout and stderr etc. is not clear

    – Engineer999
    Feb 15 at 7:12


















  • Ok thanks. It's interesting

    – Engineer999
    Feb 15 at 7:06











  • Actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. on boot-up and then all the messages from the start-up scripts when the system starts. The scripts continue to flood this terminal window as long as the system is running. However if I then connect via a different terminal on another computer using SSH over the LAN to the system, I do not see any of these debug messages flooding the screen. I'm interested to know as to why this is. Perhaps my understanding of stdout and stderr etc. is not clear

    – Engineer999
    Feb 15 at 7:12

















Ok thanks. It's interesting

– Engineer999
Feb 15 at 7:06





Ok thanks. It's interesting

– Engineer999
Feb 15 at 7:06













Actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. on boot-up and then all the messages from the start-up scripts when the system starts. The scripts continue to flood this terminal window as long as the system is running. However if I then connect via a different terminal on another computer using SSH over the LAN to the system, I do not see any of these debug messages flooding the screen. I'm interested to know as to why this is. Perhaps my understanding of stdout and stderr etc. is not clear

– Engineer999
Feb 15 at 7:12






Actually I should have explained more, I have a serial debug interface connected to my device. With this I can see all the bootloader messages etc. on boot-up and then all the messages from the start-up scripts when the system starts. The scripts continue to flood this terminal window as long as the system is running. However if I then connect via a different terminal on another computer using SSH over the LAN to the system, I do not see any of these debug messages flooding the screen. I'm interested to know as to why this is. Perhaps my understanding of stdout and stderr etc. is not clear

– Engineer999
Feb 15 at 7:12


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f500688%2fconfusion-about-stdout-and-stderr-on-the-start-up-terminal%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay