Jump to page: 1 2
Thread overview
Detect that a child is waiting for input
Nov 20, 2016
unDEFER
Nov 20, 2016
John Colvin
Nov 21, 2016
unDEFER
Nov 22, 2016
wobbles
Nov 23, 2016
unDEFER
Nov 23, 2016
wobbles
Nov 24, 2016
unDEFER
Nov 23, 2016
Shachar Shemesh
Nov 23, 2016
unDEFER
Nov 24, 2016
unDEFER
Nov 24, 2016
unDEFER
Nov 24, 2016
unDEFER
Nov 25, 2016
Shachar Shemesh
Nov 24, 2016
Shachar Shemesh
November 20, 2016
Hello!
I'm using pipeProcess() to create a process:

pipes = pipeProcess(["bash", "-c", BASH_COMMAND], Redirect.stdin | Redirect.stdout | Redirect.stderr);

Is it possible detect that the child is waiting for input on stdin?
I can't find decision even for C. I think it is impossible if the child uses unblocking reading. But I want to detect blocking reading.
November 20, 2016
On Sunday, 20 November 2016 at 12:21:19 UTC, unDEFER wrote:
> Hello!
> I'm using pipeProcess() to create a process:
>
> pipes = pipeProcess(["bash", "-c", BASH_COMMAND], Redirect.stdin | Redirect.stdout | Redirect.stderr);
>
> Is it possible detect that the child is waiting for input on stdin?
> I can't find decision even for C. I think it is impossible if the child uses unblocking reading. But I want to detect blocking reading.

If blocking is an error, you could close stdin and assuming the process checks the error codes correctly....
November 21, 2016
On Sunday, 20 November 2016 at 21:03:57 UTC, John Colvin wrote:
> If blocking is an error, you could close stdin and assuming the process checks the error codes correctly....

No, I mean blocking is not error.
One method to find it, run gdb or strace and see where the process stopped, or which syscall was last. But I believe that must be other way.
November 22, 2016
On Monday, 21 November 2016 at 07:29:55 UTC, unDEFER wrote:
> On Sunday, 20 November 2016 at 21:03:57 UTC, John Colvin wrote:
>> If blocking is an error, you could close stdin and assuming the process checks the error codes correctly....
>
> No, I mean blocking is not error.
> One method to find it, run gdb or strace and see where the process stopped, or which syscall was last. But I believe that must be other way.

Easier said than done as there's no signal the child sends to say "OK, I'm waiting now".

You can use expect to do this, if you know what the output of the child will be just before it's waiting for IO.

This is the D lib I've written to do this:
https://github.com/grogancolin/dexpect

It's not wonderful or anything, but it works :)
November 23, 2016
On 20/11/16 14:21, unDEFER wrote:
> Hello!
> I'm using pipeProcess() to create a process:
>
> pipes = pipeProcess(["bash", "-c", BASH_COMMAND], Redirect.stdin |
> Redirect.stdout | Redirect.stderr);
>
> Is it possible detect that the child is waiting for input on stdin?
> I can't find decision even for C. I think it is impossible if the child
> uses unblocking reading. But I want to detect blocking reading.

The shell does that for background processes. I think it takes away the TTY from its children, and this way, when they try to read from stdin, they get SIGSTOP from the system.

I'm not sure what the precise mechanism is.

There are flags passed to wait which will cause it to report when a child gets SIGSTOP.

Hope this helps,
Shachar
November 23, 2016
On Tuesday, 22 November 2016 at 22:30:06 UTC, wobbles wrote:
> Easier said than done as there's no signal the child sends to say "OK, I'm waiting now".
>
> You can use expect to do this, if you know what the output of the child will be just before it's waiting for IO.
>
> This is the D lib I've written to do this:
> https://github.com/grogancolin/dexpect
>
> It's not wonderful or anything, but it works :)

Thank you, good decision. Maybe I will use the idea. But how to detect that "cat" (without arguments) waits input, if it nothing prints?
November 23, 2016
On Wednesday, 23 November 2016 at 07:18:27 UTC, Shachar Shemesh wrote:
> The shell does that for background processes. I think it takes away the TTY from its children, and this way, when they try to read from stdin, they get SIGSTOP from the system.
>
> I'm not sure what the precise mechanism is.
>
> There are flags passed to wait which will cause it to report when a child gets SIGSTOP.
>
> Hope this helps,
> Shachar

Really interesting information, thank you, I will try to dig in this direction.
November 23, 2016
On Wednesday, 23 November 2016 at 15:54:30 UTC, unDEFER wrote:
> On Tuesday, 22 November 2016 at 22:30:06 UTC, wobbles wrote:
>> Easier said than done as there's no signal the child sends to say "OK, I'm waiting now".
>>
>> You can use expect to do this, if you know what the output of the child will be just before it's waiting for IO.
>>
>> This is the D lib I've written to do this:
>> https://github.com/grogancolin/dexpect
>>
>> It's not wonderful or anything, but it works :)
>
> Thank you, good decision. Maybe I will use the idea. But how to detect that "cat" (without arguments) waits input, if it nothing prints?

You dont :)

You could wait for some period of time - and if that's passed and the child hasn't printed anything you can assume it's waiting for input.
November 24, 2016
On Wednesday, 23 November 2016 at 20:02:08 UTC, wobbles wrote:
> You could wait for some period of time - and if that's passed and the child hasn't printed anything you can assume it's waiting for input.

Yes, I also have thought about it, thank you.
November 24, 2016
On Wednesday, 23 November 2016 at 07:18:27 UTC, Shachar Shemesh wrote:

> The shell does that for background processes. I think it takes away the TTY from its children, and this way, when they try to read from stdin, they get SIGSTOP from the system.
>
> I'm not sure what the precise mechanism is.
>
> There are flags passed to wait which will cause it to report when a child gets SIGSTOP.
>
> Hope this helps,
> Shachar

So, I have found with strace, this signal is SIGTTIN is special signal which sends to _background_ task when it tries to read from terminal.

So it is possible such detect when I will write not simple pipeProcess, but will write terminal emulator.
Thank you.
« First   ‹ Prev
1 2