Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27806

Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor?
Date 2014-03-21 17:14 -0400
Organization A noiseless patient Spider
Message-ID <lgia4g$v69$1@dont-email.me> (permalink)
References <1df2cef3-b358-465c-9d56-1c8739a17051@googlegroups.com>

Show all headers | View raw


On 3/21/2014 4:13 PM, www wrote:
> a program currently running is printing something to the terminal. I am wondering if I can use some Java to intercept those printed message so that those message do not show up on the terminal.
>
> That program is not started by the Java program. I am working on Linux.
>
> My understanding of file system is that there is a filedescriptor 0 -- the keyboard input are saved in that file and other programs take it from there; there is another filesdescriptor 1 -- the messages printed by computer programs are put into that file first, then its content is dumped to the monitor. So I think if I can let Java code erase my computer filedescriptor 1, then nothing will be printed to the monitor. file descriptor 2 is another file and is for the stderr.

     Every Unix process has its own set of file descriptors.[*]
There is no system-wide "file descriptor 1" that program A could
somehow erase or make unavailable to program B.  (If there were
such a system-wide thing and A deleted it, it would also become
unavailable to programs C,D,E,...,Z,AA,AB,...)

     Also, your notions about buffering input and output in files
while it's in transit between programs and devices are a little
wide of the mark.  A "file descriptor" need not refer to a disk
file; it can refer to anything that satisfies Unix' abstract
notion of "file:" disk file, tty, socket, pipe, ...  There is
no on-disk file whose deletion would cause the program's output
to go somewhere else than it's already going.  (Well, I suppose
you could suppress the program's output by deleting so many
crucial system files that the whole O/S came crashing down in
flaming ruins -- but you might not want to do that...)

     [*] Sometimes two or more processes can share a single file
descriptor.  This happens most often when a parent process uses
a process-creating system call like fork(), and the child process
inherits all the parent's open descriptors.  There are also some
fairly "advanced" techniques that allow one process to create a
file descriptor and share it with another already-running process.
But in the ordinary scheme of things, two "unrelated" processes --
like your printing program and your Java program -- have no file
descriptors in common.

> I think this is an interesting exercise for me.

     I think two things: First, that you should learn about the
"/dev/null" pseudo-device and how to do I/O redirection, and
second, that your question will get better answers in
comp.unix.programmer than here.

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

can Java program abolish file descriptor 1 so no any programs can print to the monitor? www <xsli2@yahoo.com> - 2014-03-21 13:13 -0700
  Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-21 17:14 -0400
  Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor? Roedy Green <see_website@mindprod.com.invalid> - 2014-03-21 15:54 -0700
    Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor? Joerg Meier <joergmmeier@arcor.de> - 2014-03-21 23:59 +0100
      Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor? Roedy Green <see_website@mindprod.com.invalid> - 2014-03-22 02:32 -0700
        Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor? Joerg Meier <joergmmeier@arcor.de> - 2014-03-22 11:33 +0100
          Re: can Java program abolish file descriptor 1 so no any programs can print to the monitor? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-22 11:24 +0000

csiph-web