2

I have a program that fork()s and exits. Its child remains running for about 50 seconds, while it prints out messages each 5 seconds. When I run from a terminal it runs as expected, the parent exits, then the child prints 10 messages and exits too. I then created a systemd service unit with only this:

[Unit]
Description=Program that forks
Documentation=https://program5.example.com

[Service]
Type=forking
ExecStart=/root/fork

Apparently systemd works as it shows the main process active until the child exits, but checking journalctl or even looking at the program with systemctl status, the child messages on the screen only shows up after the child exits and the process is dead. Why is that?

  • 3
    It's the buffering question yet again. See https://unix.stackexchange.com/questions/505146/, https://unix.stackexchange.com/questions/285419 , https://unix.stackexchange.com/questions/164987 , https://unix.stackexchange.com/questions/68059 , https://unix.stackexchange.com/questions/206224 , and https://unix.stackexchange.com/questions/164987 . – JdeBP Mar 10 '19 at 01:35
  • 1
    unfortunately my program was in C and none of the links you posted helped me as they were all for Python. At least I understood it had to do with POSIX way of doing things and and how the OS was delaying the clearing of buffers to stdout, so I found out this: https://www.turnkeylinux.org/blog/unix-buffering. I understood I had to clean the buffer myself with fflush(stdout) in my case. – Adriano_epifas Mar 10 '19 at 19:57

0 Answers0