# Where stdout/stderr go for programs launched from inittab?

## peaceful

I've got a python script that I start from inittab and I can't figure out where it's stdout/stderr output go to.  They certainly don't go to /var/log/messages or any other file I see in /var/log.  Does anyone know where they go?

----------

## manaka

Well... AFAIK, a process launched from init has no file opened... So when your script tries to write to stdout/stderr (file descriptors 2 and 3), it will get an error. If you catch exceptions/errors, the process should end execution... Anyway, the messages are lost since you cannot see them...  :Sad: 

You can try redirecting them to a file... (the usual sh redirection should work here, since init uses sh to spawn the processes, AFAIK)...

A better way would be logging through syslog... It makes more sense for a process launched for init..

----------

## peaceful

 *manaka wrote:*   

> Well... AFAIK, a process launched from init has no file opened... So when your script tries to write to stdout/stderr (file descriptors 2 and 3), it will get an error. If you catch exceptions/errors, the process should end execution... Anyway, the messages are lost since you cannot see them... 
> 
> You can try redirecting them to a file... (the usual sh redirection should work here, since init uses sh to spawn the processes, AFAIK)...
> 
> A better way would be logging through syslog... It makes more sense for a process launched for init..

 

My script definitely does not get errors when it writes to stdout/stderr--it would unceremoniously crash if it did.

That's good to know about being launched by sh, though.  I'll just try redirecting the output, then.  Thanks!

----------

## Hu

You can use lsof -p pid-of-script to see its open descriptors.  Descriptors 0, 1, and 2 are stdin, stdout, and stderr.  A quick check on a standard getty shows that it has stdin/stdout/stderr all bound to the tty that it controls.  However, this may be a function of how getty handles its descriptors, rather than a function of how init spawned it.

----------

## manaka

Have researched a bit the details about this... Seems I was wrong  :Embarassed: ... Processes spawned by init have as file descriptors 0, 1 and 2 the char device /dev/console ... Have tried adding the following line to /etc/inittab:

```

test:b:once:/bin/sleep 30

```

Then we tell init to reread its configuration and execute runlevel B procesess:

```

telinit Q

telinit B

```

Now we see that the sleep process has /dev/console open:

```

m1 ~ # lsof -c sleep

COMMAND   PID USER   FD   TYPE DEVICE    SIZE   NODE NAME

sleep   31911 root  cwd    DIR  254,1    1024      2 /

sleep   31911 root  rtd    DIR  254,1    1024      2 /

sleep   31911 root  txt    REG  254,1   23268 122932 /bin/sleep

sleep   31911 root  mem    REG  254,1 1249516  36872 /lib/libc-2.6.1.so

sleep   31911 root  mem    REG  254,1  108996  37042 /lib/ld-2.6.1.so

sleep   31911 root    0u   CHR    5,1           3043 /dev/console

sleep   31911 root    1u   CHR    5,1           3043 /dev/console

sleep   31911 root    2u   CHR    5,1           3043 /dev/console

```

As for the initial question by peaceful, the output should go to the "system console"... Usually it's the current virtual terminal (the one selected by Alt-F1, Alt-F2, ...). If you are running an X session, the current virtual terminal is the one displaying all the windows... If this is the case, you wouldn't see the messages... (They are not lost, they cannot be seen)...

----------

