Shell script sending some message to already running process(which written in c)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can some one please help me on, communication mechanism between shell script and an daemon which is written C. Want to exchange messages between shell script(bash) and an process.
Ok...so what, exactly, do you need help WITH?? You've posted no code, no details about what you're trying to do, etc. We can't guess. Shells typically have return codes on commands that can be read in a variety of ways.
Can some one please help me on, communication mechanism between shell script and an daemon which is written C.
Want to exchange messages between shell script(bash) and an process.
Signals and pipes are some options. You should read Chapter 6.
If you wish, in my name on the left side, there's a link to my blog overall and in there are several ancient discussions with examples for things like a daemon communicating with child processes, and so forth, also the use of the select() call, pipes, signals. It's spread around across the Linux Application category, or whatever I named it, there's 3 or 4 from 8-10 years ago.
For shell to process, there are signals and also the return status. Say for instance a shell script is run from within a Linux C application, that application can monitor using wait or waitv for the termination signals from that child (the script) and it can also check exit status.
If the script runs continually, well when it gets spawned from the C code, (or vice versa, script spawning a C application), pipes can be created in advance and then used to communicate between each side. Note pipes are half duplex, so you'll need 2 of them. Examples shown in those blogs.
This is not some "one of + quick" thing, you'll need to study the topic and decide what works for you and develop plus test the results incrementally. All the code shown in those blogs was not written in an afternoon, more like a few weeks or longer.
As others have said, we're happy to help, but you'll need to study up on the topic and try some things on your own to be able to ask next level types of questions.
The classical way to do this is with "pipes" – implemented by the "|" character on the command-line.
Every Linux/Unix process automatically has three file-handles: STDIN, STDOUT, STDERR.
The "C" program can be written to simply expect to read commands from its STDIN file, and to write its outputs to one of the other two. Now, you can simply issue a console command which invokes several programs at the same time, "piping" their inputs and outputs from one to the next. If you set things up in this way, you don't even have to write a separate program: the shell will do it for you.
It was a great idea in the 1970's, and it's still a great idea today.
To clarify – command-line "|" piping simply uses STDIN and STDOUT. The shell parses the command line, creates the child processes, pipes the STDOUT of one to the STDIN of the next (redirection of STDERR takes a few more keystrokes on your part), then lets them go. The shell then sleeps until all of the children terminate.
I would ask first if OP has access to the running binary's src or manual.
We are assuming he does and it is written to be communicated with this way (or can be changed to do so).
It's entirely possible it's a 3rd party binary and it's not built that way ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.