public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Freeze opening /dev/stdout
@ 2018-07-20 16:08 João Eiras
  2018-07-21  7:04 ` Takashi Yano
  0 siblings, 1 reply; 5+ messages in thread
From: João Eiras @ 2018-07-20 16:08 UTC (permalink / raw)
  To: cygwin

Hi.

On linux now and then I call a program passing "/dev/stdout" as output
file parameter, so the data is output in the terminal.

For instance, something tiny in C.

#include <fcntl.h>
#include <stdio.h>
int main () {
int fd = open("/dev/stdout", O_WRONLY);
printf("Opened stdout: %d\n", fd);
return 0;
}

Unfortunately, this freezes. The problem (I think) is because
/dev/stdout is a pipe, so the open() call waits forever until a
reader() opens /dev/stdout, which in this case should be the terminal.

Interestingly, this does not affect /dev/stderr which is a link to the
console device.

$ ls -la /dev/std*
lrwxrwxrwx 1 user None 15 Sep  6  2017 /dev/stderr -> /proc/self/fd/2
prw------- 1 user None  0 Jun  4 15:54 /dev/stdin
prw------- 1 user None  0 Jun  4 15:54 /dev/stdout

I've just sent another thread about "/dev/stdin" always being a pipe,
so I guess that is related.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Freeze opening /dev/stdout
  2018-07-20 16:08 Freeze opening /dev/stdout João Eiras
@ 2018-07-21  7:04 ` Takashi Yano
  2018-07-21 11:30   ` Marco Atzeri
  2018-07-21 14:56   ` Takashi Yano
  0 siblings, 2 replies; 5+ messages in thread
From: Takashi Yano @ 2018-07-21  7:04 UTC (permalink / raw)
  To: cygwin

On Fri, 20 Jul 2018 15:35:21 +0200
João Eiras wrote:
> #include <fcntl.h>
> #include <stdio.h>
> int main () {
> int fd = open("/dev/stdout", O_WRONLY);
> printf("Opened stdout: %d\n", fd);
> return 0;
> }
> 
> Unfortunately, this freezes. The problem (I think) is because
> /dev/stdout is a pipe, so the open() call waits forever until a
> reader() opens /dev/stdout, which in this case should be the terminal.

I can't reporduce your problem.

The test case outputs:
Opened stdout: 3

$ ls -la /dev/std*
lrwxrwxrwx 1 yano なし 15 Mar 26  2016 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 yano なし 15 Mar 26  2016 /dev/stdin -> /proc/self/fd/0
lrwxrwxrwx 1 yano なし 15 Mar 26  2016 /dev/stdout -> /proc/self/fd/1

What happens if you execute:
rm /dev/stdin /dev/stdout
ln -s /proc/self/fd/0 /dev/stdin
ln -s /proc/self/fd/1 /dev/output

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Freeze opening /dev/stdout
  2018-07-21  7:04 ` Takashi Yano
@ 2018-07-21 11:30   ` Marco Atzeri
  2018-07-21 14:56   ` Takashi Yano
  1 sibling, 0 replies; 5+ messages in thread
From: Marco Atzeri @ 2018-07-21 11:30 UTC (permalink / raw)
  To: cygwin

Am 21.07.2018 um 03:19 schrieb Takashi Yano:
> On Fri, 20 Jul 2018 15:35:21 +0200
> João Eiras wrote:
>> #include <fcntl.h>
>> #include <stdio.h>
>> int main () {
>> int fd = open("/dev/stdout", O_WRONLY);
>> printf("Opened stdout: %d\n", fd);
>> return 0;
>> }
>>
>> Unfortunately, this freezes. The problem (I think) is because
>> /dev/stdout is a pipe, so the open() call waits forever until a
>> reader() opens /dev/stdout, which in this case should be the terminal.
> 
> I can't reporduce your problem.
> 
> The test case outputs:
> Opened stdout: 3
> 

same here.
$ ./prova.exe
Opened stdout: 3

João, what exacly is your enviroment and terminal ?


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Freeze opening /dev/stdout
  2018-07-21  7:04 ` Takashi Yano
  2018-07-21 11:30   ` Marco Atzeri
@ 2018-07-21 14:56   ` Takashi Yano
  2018-07-21 19:22     ` João Eiras
  1 sibling, 1 reply; 5+ messages in thread
From: Takashi Yano @ 2018-07-21 14:56 UTC (permalink / raw)
  To: cygwin

On Sat, 21 Jul 2018 10:19:03 +0900
Takashi Yano wrote:
> What happens if you execute:
> rm /dev/stdin /dev/stdout
> ln -s /proc/self/fd/0 /dev/stdin
> ln -s /proc/self/fd/1 /dev/output

This is typo.

s/output/stdout/

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Freeze opening /dev/stdout
  2018-07-21 14:56   ` Takashi Yano
@ 2018-07-21 19:22     ` João Eiras
  0 siblings, 0 replies; 5+ messages in thread
From: João Eiras @ 2018-07-21 19:22 UTC (permalink / raw)
  To: cygwin

Thanks everyone.

Turns out it's some problem with my setup that is affecting stdin and
stdout. I had no idea that could happen.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

end of thread, other threads:[~2018-07-21 14:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-20 16:08 Freeze opening /dev/stdout João Eiras
2018-07-21  7:04 ` Takashi Yano
2018-07-21 11:30   ` Marco Atzeri
2018-07-21 14:56   ` Takashi Yano
2018-07-21 19:22     ` João Eiras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).