LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2023, 07:49 AM   #1
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Location: Non. Je suis propriétaire – No. I am an owner.
Distribution: Apple-selling shops, markets and direct marketing
Posts: 1,482
Blog Entries: 39

Rep: Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772
[C/C++] arguments to child process.


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:
Code:
rv = posix_fcntl(fd_out[1], POSIX_F_SETFL, POSIX_O_NONBLOCK);
if(-1 != rv)
  {
     rv = posix_fcntl(fd_in[0], POSIX_F_SETFL, POSIX_O_NONBLOCK);
  }
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.

Thank you
 
Old 04-25-2023, 09:26 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,954

Rep: Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215
Quote:
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).

Last edited by dugan; 04-25-2023 at 12:46 PM.
 
Old 04-26-2023, 12:58 PM   #3
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Location: Non. Je suis propriétaire – No. I am an owner.
Distribution: Apple-selling shops, markets and direct marketing
Posts: 1,482

Original Poster
Blog Entries: 39

Rep: Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772
Quote:
Originally Posted by dugan View Post
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
 
Old 04-26-2023, 03:17 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,954

Rep: Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215
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.

Last edited by dugan; 04-26-2023 at 11:38 PM.
 
Old 04-27-2023, 07:30 AM   #5
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Location: Non. Je suis propriétaire – No. I am an owner.
Distribution: Apple-selling shops, markets and direct marketing
Posts: 1,482

Original Poster
Blog Entries: 39

Rep: Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772
Quote:
Originally Posted by dugan View Post
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.
 
Old 04-27-2023, 08:11 AM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,954

Rep: Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215
Link to the actual code you’re asking us to help you look at.
 
Old 04-27-2023, 09:07 AM   #7
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 3,994

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
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.
 
Old 04-28-2023, 03:24 AM   #8
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Location: Non. Je suis propriétaire – No. I am an owner.
Distribution: Apple-selling shops, markets and direct marketing
Posts: 1,482

Original Poster
Blog Entries: 39

Rep: Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772Reputation: 772
Quote:
Originally Posted by smallpond View Post
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.

Cheerio.
 
  


Reply

Tags
execl(), fork(), stdin


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Child THREAD and Child PROCESS whho Linux - Newbie 12 02-16-2015 12:22 AM
passing arguments to a child process in C++ bhanuvrat Programming 7 02-07-2010 10:01 PM
Under which circumstances a child process creates another child process using fork? mitsulas Programming 3 12-08-2009 08:16 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
Killing a child process from another child marri Programming 6 10-01-2004 07:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration