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.
I am *not* programming this but try to understand a program. I have a feature-request in mind but cannot say, if it makes sense: Allow an external process to receive an optional argument,
Situation as I interpret it:
In a fork()-induced child process, an external routine is started with execl(), posix_execl being an alias:
Code:
posix_execl(path, pathname, (char*) NULL);
Then, in the main-process, the pipes are set for IPC:
Afterwards, the content of a text-file is fed to the STDIN of the running external program.
Code:
rv3 = posix_write(fd_out[1], (void*) &content[i], len - i);
My question:
I understand that the external routine receives arguments in the call to execl(). But if the actual content which is piped to STDIN – in the last line of code above – sets a condition, how would you communicate this condition to the external process?
Let's say the content can be of diverse nature and the specific type of content should be known to the external program ...
As I see it, my idea does not justify the profound changes which it would necessitate.
This is basically about execl() and write(), but please say, if my scenario is not clear.
But if the actual content which is piped to STDIN – in the last line of code above – sets a condition, how would you communicate this condition to the external process?
That would be communicated via the actual content that is piped to the external process' STDIN. Which the external process reads and presumably understands.
Did I miss something?
(If you just open a text file and pipe its contents into a child process, then the contents of that file would not be setting a condition. Code in either the parent or child process would be setting the condition).
That would be communicated via the actual content that is piped to the external process' STDIN. Which the external process reads and presumably understands.
Did I miss something?
No, but I may have expressed myself poorly. What I am hoping for, is a way to communicate an optional additional value – as an argument – to the external process. It should certainly be possible to define a delimiter and then to append anything to the text which is piped-in to STDIN, but as I would like the additional data to be optional, an argument would probably be better.
As I see it, the “additional data” must already be known upon calling execl() or the whole procedure would have to be changed, in a way that I do not understand and which can have too many consequences. In both cases, I refrain from suggesting a new feature.
Last edited by Michael Uplawski; 04-26-2023 at 01:00 PM.
Reason: cosmetics
Are you asking if you could code the child process to take a command-line argument, and also code the parent process to launch it with that command-line argument?
If you're writing the child process, then that's easy.
Are you asking if you could code the child process to take a command-line argument, and also code the parent process to launch it with that command-line argument?
If you're writing the child process, then that's easy.
I have done that... but have never used the technique of the program I am talking about: The Newsreader flnews.
My code to launch an external application contained all, the path to the program and all possible arguments. What I see here is a process which is started *without* any arguments but will later processes data that comes in via STDIN, a text in this case.
What I am wondering about is,
whether the arguments could come to existence *only when* the data to pipe into the child process is available
whether this will need a different function than execl(), a modification that I consider too important.
(most of all) whether I miss something and thus cannot (yet) evaluate the consequences of my potential feature request.
Maybe shared memory would help, but I cannot say what the caveats are.
Put another way, my C-knowledge is rotten and dates from many standards ago.
Last edited by Michael Uplawski; 04-27-2023 at 07:32 AM.
Command line arguments must exist when the program is started. There is no standard mechanism to add more elements to argv later, or any way to tell a program to look at it's arguments again. Of course you could come up with your own nonstandard way, but it seems far more complicated than other ways to provide input to a program: files, signals, shared memory, sockets, etc.
Command line arguments must exist when the program is started. There is no standard mechanism to add more elements to argv later, or any way to tell a program to look at it's arguments again. Of course you could come up with your own nonstandard way, but it seems far more complicated than other ways to provide input to a program: files, signals, shared memory, sockets, etc.
Thank you.
Without wanting to modify profoundly the program, appending to the pipe appears to be the simplest way to implement my idea. The problem is then only, that the receiving process must be prepared to parse *or to actively ignore* the additional data.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.