caml-list - the Caml user's mailing list
 help / Atom feed
* [Caml-list] Determination of the identification for the last started background process
@ 2021-01-06 14:05 Markus Elfring
  2021-01-06 14:41 ` Gabriel Scherer
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2021-01-06 14:05 UTC (permalink / raw)
  To: caml-list

Hello,

The programming language “OCaml” supports also to start a background process
by the function “Unix.system”.
How can the corresponding process identification be determined?

I would appreciate your advices.

Regards,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-06 14:05 [Caml-list] Determination of the identification for the last started background process Markus Elfring
@ 2021-01-06 14:41 ` Gabriel Scherer
  2021-01-09 16:08   ` Markus Elfring
  0 siblings, 1 reply; 12+ messages in thread
From: Gabriel Scherer @ 2021-01-06 14:41 UTC (permalink / raw)
  To: Markus Elfring; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

You may be looking for the

  Unix.create_process

function:
https://ocaml.org/releases/4.11/htmlman/libref/Unix.html#1_Highlevelprocessandredirectionmanagement

On Wed, Jan 6, 2021 at 3:05 PM Markus Elfring <Markus.Elfring@web.de> wrote:

> Hello,
>
> The programming language “OCaml” supports also to start a background
> process
> by the function “Unix.system”.
> How can the corresponding process identification be determined?
>
> I would appreciate your advices.
>
> Regards,
> Markus
>

[-- Attachment #2: Type: text/html, Size: 984 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-06 14:41 ` Gabriel Scherer
@ 2021-01-09 16:08   ` Markus Elfring
  2021-01-09 16:34     ` Gabriel Scherer
  2021-01-09 17:26     ` Oliver Bandel
  0 siblings, 2 replies; 12+ messages in thread
From: Markus Elfring @ 2021-01-09 16:08 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

> You may be looking for the
>
>   Unix.create_process

This function needs more input parameters than “Unix.system”.
https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process

Now I am curious which datum should be passed for the argument “stdin”
if a program should be executed as a child process without extra standard input?

Regards,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-09 16:08   ` Markus Elfring
@ 2021-01-09 16:34     ` Gabriel Scherer
  2021-01-09 16:43       ` [Caml-list] Creation of a child process without extra standard input? Markus Elfring
  2021-01-09 16:45       ` [Caml-list] Determination of the identification for the last started background process Xavier Leroy
  2021-01-09 17:26     ` Oliver Bandel
  1 sibling, 2 replies; 12+ messages in thread
From: Gabriel Scherer @ 2021-01-09 16:34 UTC (permalink / raw)
  To: Markus Elfring; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 819 bytes --]

My understanding is that if "prog" is the name of the program to run, then

  Unix.system (Filename.quote_command prog args)

is equivalent to

  Unix.create_process prog args ~stdin:Unix.stdin ~stdout:Unix.stdout
~stderr:Unix.stderr

or (shorter)

  Unix.(create_process prog args ~stdin ~stdour ~stderr)

On Sat, Jan 9, 2021 at 5:08 PM Markus Elfring <Markus.Elfring@web.de> wrote:

> > You may be looking for the
> >
> >   Unix.create_process
>
> This function needs more input parameters than “Unix.system”.
>
> https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process
>
> Now I am curious which datum should be passed for the argument “stdin”
> if a program should be executed as a child process without extra standard
> input?
>
> Regards,
> Markus
>

[-- Attachment #2: Type: text/html, Size: 1401 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Creation of a child process without extra standard input?
  2021-01-09 16:34     ` Gabriel Scherer
@ 2021-01-09 16:43       ` Markus Elfring
  2021-01-09 16:45       ` [Caml-list] Determination of the identification for the last started background process Xavier Leroy
  1 sibling, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2021-01-09 16:43 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

> My understanding is that if "prog" is the name of the program to run, then
>
>   Unix.system (Filename.quote_command prog args)
>
> is equivalent to
>
>   Unix.create_process prog args ~stdin:Unix.stdin ~stdout:Unix.stdout ~stderr:Unix.stderr

Thanks for another feedback.

But I wonder how it fits to the programming concern for the omission of a standard input selection
(because an input file would be specified within the data for the parameter “args”).

Regards,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-09 16:34     ` Gabriel Scherer
  2021-01-09 16:43       ` [Caml-list] Creation of a child process without extra standard input? Markus Elfring
@ 2021-01-09 16:45       ` Xavier Leroy
  2021-01-09 16:52         ` Markus Elfring
  1 sibling, 1 reply; 12+ messages in thread
From: Xavier Leroy @ 2021-01-09 16:45 UTC (permalink / raw)
  To: caml users

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

On Sat, Jan 9, 2021 at 5:34 PM Gabriel Scherer <gabriel.scherer@gmail.com>
wrote:

> My understanding is that if "prog" is the name of the program to run, then
>
>   Unix.system (Filename.quote_command prog args)
>
> is equivalent to
>
>   Unix.create_process prog args ~stdin:Unix.stdin ~stdout:Unix.stdout
> ~stderr:Unix.stderr
>

Not quite: args should be Array.of_list (prog :: args).  Argument number 0
is, by Unix convention, the name of the program.

The original poster may be looking for the Unix.open_process family of
functions.

- Xavier Leroy




> or (shorter)
>
>   Unix.(create_process prog args ~stdin ~stdour ~stderr)
>
> On Sat, Jan 9, 2021 at 5:08 PM Markus Elfring <Markus.Elfring@web.de>
> wrote:
>
>> > You may be looking for the
>> >
>> >   Unix.create_process
>>
>> This function needs more input parameters than “Unix.system”.
>>
>> https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process
>>
>> Now I am curious which datum should be passed for the argument “stdin”
>> if a program should be executed as a child process without extra standard
>> input?
>>
>> Regards,
>> Markus
>>
>

[-- Attachment #2: Type: text/html, Size: 2414 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-09 16:45       ` [Caml-list] Determination of the identification for the last started background process Xavier Leroy
@ 2021-01-09 16:52         ` Markus Elfring
  2021-01-09 17:30           ` Oliver Bandel
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2021-01-09 16:52 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml-list

> The original poster may be looking for the Unix.open_process family of functions.

This looks unlikely when these function variants do not return an identification
for the started child process.

Regards,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-09 16:08   ` Markus Elfring
  2021-01-09 16:34     ` Gabriel Scherer
@ 2021-01-09 17:26     ` Oliver Bandel
  2021-01-09 17:52       ` Markus Elfring
  2021-01-10  9:00       ` [Caml-list] Specification of an input file for a child process Markus Elfring
  1 sibling, 2 replies; 12+ messages in thread
From: Oliver Bandel @ 2021-01-09 17:26 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Gabriel Scherer, caml-list



> Am 09.01.2021 um 17:08 schrieb Markus Elfring <Markus.Elfring@web.de>:
> 
> 
>> 
>> You may be looking for the
>> 
>>   Unix.create_process
> 
> This function needs more input parameters than “Unix.system”.
> https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process
> 
> Now I am curious which datum should be passed for the argument “stdin”
> if a program should be executed as a child process without extra standard input?
[...]

It would be much easier to point you to the right functions, if you would give some  more details on what you want to do, e.g. an example command that you want to use, and to tell us, if you want to pass data into it or read data from it, and so on.
The less information you provide, the fuzzier / general the anwers.

It might also interest you, that there is a seperated manual on how to do unix-programming with OCaml.

Ciao,
  Oliver




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-09 16:52         ` Markus Elfring
@ 2021-01-09 17:30           ` Oliver Bandel
  2021-01-09 18:00             ` Markus Elfring
  0 siblings, 1 reply; 12+ messages in thread
From: Oliver Bandel @ 2021-01-09 17:30 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Xavier Leroy, caml-list



> Am 09.01.2021 um 17:52 schrieb Markus Elfring <Markus.Elfring@web.de>:
> 
> 
>> 
>> The original poster may be looking for the Unix.open_process family of functions.
> 
> This looks unlikely when these function variants do not return an identification
> for the started child process.

Do you mean the process ID, when talking about "an identification"?
Do you really need it?

You may want to look for fork, exec and pipe....

Ciao,
   Oliver



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-09 17:26     ` Oliver Bandel
@ 2021-01-09 17:52       ` Markus Elfring
  2021-01-10  9:00       ` [Caml-list] Specification of an input file for a child process Markus Elfring
  1 sibling, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2021-01-09 17:52 UTC (permalink / raw)
  To: Oliver Bandel; +Cc: Gabriel Scherer, caml-list

>> https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process
>>
>> Now I am curious which datum should be passed for the argument “stdin”
>> if a program should be executed as a child process without extra standard input?
> [...]
>
> It would be much easier to point you to the right functions,

Thanks for your growing development interest.


> if you would give some  more details on what you want to do,

I became interested in the safe handling of commands for PostScript viewers.


> e.g. an example command that you want to use, and to tell us, if you want to pass data into it or read data from it, and so on.

Would you like to add any comments to background information
which was provided for code review with the commit “add error checking” (from 2020-12-24)
for an evolving software?
https://github.com/coccinelle/coccinelle/commit/4127b5546ccd929ae017565e710a3c9092f0bb0c

Regards,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Determination of the identification for the last started background process
  2021-01-09 17:30           ` Oliver Bandel
@ 2021-01-09 18:00             ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2021-01-09 18:00 UTC (permalink / raw)
  To: Oliver Bandel; +Cc: Xavier Leroy, caml-list

> Do you mean the process ID, when talking about "an identification"?

Yes.


> Do you really need it?

I imagine that a PID will be needed so that a corresponding wait function call
can be performed finally.
https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALwaitpid

Regards,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Specification of an input file for a child process
  2021-01-09 17:26     ` Oliver Bandel
  2021-01-09 17:52       ` Markus Elfring
@ 2021-01-10  9:00       ` Markus Elfring
  1 sibling, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2021-01-10  9:00 UTC (permalink / raw)
  To: Oliver Bandel, caml-list; +Cc: Gabriel Scherer

> The less information you provide, the fuzzier / general the anwers.
>
> It might also interest you, that there is a seperated manual on how to do unix-programming with OCaml.

I stumbled on general function properties for this programming interface.

* Which process should open an input file for a child process?

* Which functions do return an identification (a PID) for the started child process accordingly?

Regards,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, back to index

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 14:05 [Caml-list] Determination of the identification for the last started background process Markus Elfring
2021-01-06 14:41 ` Gabriel Scherer
2021-01-09 16:08   ` Markus Elfring
2021-01-09 16:34     ` Gabriel Scherer
2021-01-09 16:43       ` [Caml-list] Creation of a child process without extra standard input? Markus Elfring
2021-01-09 16:45       ` [Caml-list] Determination of the identification for the last started background process Xavier Leroy
2021-01-09 16:52         ` Markus Elfring
2021-01-09 17:30           ` Oliver Bandel
2021-01-09 18:00             ` Markus Elfring
2021-01-09 17:26     ` Oliver Bandel
2021-01-09 17:52       ` Markus Elfring
2021-01-10  9:00       ` [Caml-list] Specification of an input file for a child process Markus Elfring

caml-list - the Caml user's mailing list

Archives are clonable: git clone --mirror https://inbox.ocaml.org/caml-list

AGPL code for this site: git clone https://public-inbox.org/ public-inbox