Why all output of my C program directed to stdout is sent to journald?
1
vote
2
answers
1581
views
I work on yocto based linux distribution. I'm not expert about
systemd
and neither about systemd-journald
.
My C program my_c_program
is started at boot by the script my_script.sh
. Below there is the file my_script.sh
:
my_c_program &
echo $! > /dev/shm/my_c_program.pid
Previous script is started by a service. The unit file of the service is called start_c_program.service
. Below there is the unit service:
[Unit]
Description=Start my_c_program
Requires=...
After=...
Before=...
[Service]
Type=forking
ExecStart=/usr/bin/my_script.sh
PIDFile=/dev/shm/my_c_program.pid
[Install]
WantedBy=multi-user.target
With this configuration all instructions printf("message")
present in my_c_program
add the string "message"
to systemd-journald
.
I know that if I modify my_script.sh
to:
my_c_program > /dev/null &
echo $! > /dev/shm/my_c_program.pid
the message on journald
are suppressed, but the question is:
why all output of my C program directed to stdout is sent to journald
?
Thanks
___
I was thinking that to send message to journald
I had to use the C instruction syslog()
, for example by a code as below:
#include
int main(int argc, char** argv) {
syslog(LOG_INFO, "Start logging");
}
Asked by User051209
(498 rep)
Apr 7, 2023, 08:07 AM
Last activity: Feb 21, 2025, 05:25 PM
Last activity: Feb 21, 2025, 05:25 PM