1

I suspect a process not to send EOF when killed with SIGINT and SIGKILL respectively. Can that be the case (or do all processes always send EOF to stdout and stderr after being terminated with whatever signal)? If yes, how can I immitate such a process so that I can use it in a Java unit test (which needs to run on Linux only for starters)?

The english Wikipedia EOF article isn't clear about that, the german says that EOF "may" be sent.

I'm aware of the fact this is probably an XY problem and asking for support in debugging the Java code would get things fixes more quickly, but I'm interested in a getting an answer to this question as well. I'm also aware that process handling has been improved in Java 9 which I can't use yet.

I'm using Ubuntu 17.04 with Linux 4.10.

  • No process sends anything after SIGKILL. – Hauke Laging Aug 19 '17 at 20:32
  • That explains a lot. That answers the question, doesn't it? – Karl Richter Aug 19 '17 at 20:38
  • That would answer the question only if there were no other signals. – Hauke Laging Aug 19 '17 at 20:42
  • 1
    AFAIK, EOF isn't something that is sent, it's the state of an input stream. – Kusalananda Aug 19 '17 at 20:52
4

An EOF isn't really "sent". It's an event where your process calls the read system call and it returns 0, which for pipes happens when the other end of the pipe has been closed (by all processes that have it, if the filedescriptor has been duplicated).

The kernel will always close all filedescriptors in terminating processes. There's no way around it (even filedescriptors of SIGKILL'ed processes get closed). If any of those filedescriptors is a last reference to a pipe filedescriptor write end, the nextread on the corresponding read end will return 0, which stdio will interpret as an EOF.

-1

It is probably not a problem if several EOF characters are sent. Thus you can run your Java program together with shell code that outputs EOF after the Java program has exited.

( javaprog ; echo -n $'\4' ) | program_waiting_for_eof

Some configuration for the signal handling is necessary, though, to ensure that the Java process is killed but the followong code still executed. If this is a suitable approach for you (which you may test by killing the Java process directly with kill $PID from another terminal) then I can provide additional information hwo to do that if you need it.

  • The process I suspect to not send EOF isn't necessarily a Java program/program interpreted by java, but can be any process I control from within a Java program. The program in question is PostgreSQL's server binary postgres. – Karl Richter Aug 20 '17 at 3:25
  • @KarlRichter That does not make a difference in this case. – Hauke Laging Aug 20 '17 at 7:34
  • 2
    @HaukeLaging EOT (ASCII character 4) is not EOF (lack of any character) – Fox Aug 20 '17 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.