Reputation: 1315
What is the best solution to get values known in shell into the C binary application during its run-time?
The C application communicates with third party product and sends it actual settings. But some settings are changed directly in OS, so I want to use some command from shell to influence, change, these variables in C application.
Do you know some way for achieving it (using variable, pipes, or maybe something differently other)?
I looked at global variables, but even though I change global variable value, it has no effect in C application which was running all time. (I used function getenv()).
Upvotes: 1
Views: 132
Reputation: 66323
Most long running processes (aka. daemon) in Unix have some kind of configuration files (e.g. /etc/mydaemon.conf
) which they read (and evaluate)
HUP
signal.So the most easiest and well-known way is to install a signal handler in the C app and catch SIGHUP signals. This of course requires changes to the C app.
To trigger a reread in the shell you can use one of these commands:
kill -HUP PID_OF_MY_PROCESS
pkill -HUP name_of_my_process
Upvotes: 5
Reputation: 400159
You can't change environment variables after the process has been started. They are inherited into the process, but once that's happened the values cannot be changed from outside the process.
Look into all the usual method of inter-process communication, such as (like you mention) sockets, pipes, shared memory etc.
Upvotes: 1