I
I
Insolent Muzzle2022-02-20 04:20:03
Operating Systems
Insolent Muzzle, 2022-02-20 04:20:03

How do languages ​​running on a VM write to the console?

I wanted to know how console output works under the hood. I know that data is simply written to stdout, but two questions arise here: 1. How do programs find this very stdout? 2. How do they write data to it?

I would like to know how it works exactly in the case of languages ​​like Java or C #, because with low-level languages ​​everything is more or less clear (I heard that in unix-like systems this stdout is in / dev / fd / 1 and write data into it using the POSIX API).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2022-02-20
@pluffie

stdout is just a handle that opens the console.
For each console program, three descriptors with numbers 0, 1, 2 (stdin, stdout, stderr) are opened, where they can write.
/dev/fd/1
No, fd is just a file descriptor/1
, the correct path would be /proc/process_id/fd/1
i.e. each process has its own stdout.
Well, more. It doesn't matter what language. This is about the operating system architecture, not the language.

H
hint000, 2022-02-20
@hint000

how it works exactly in the case of languages ​​like Java or C#
This is hidden in library functions and the programmer may not think about how it works. You call the standard output function and it does all the work. Examples:
https://ru.wikipedia.org/wiki/Printf
https://prog-cpp.ru/cpp-std/
you can write data to it using the POSIX API
It may be possible. But in fact, everyone uses the same library functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question