Showing results for 
Search instead for 
Did you mean: 
1 View

ifort hangs at 100% CPU if input from stdin is not newline-terminated

        program test_read_stdin

        implicit none
        character*200 line

10      read(*,'(a)', end=20,err=30) line
        write(0,'(a)') line
        goto 10
20      write(0,'(a)') 'EOF'
30      write(0,'(a)') 'ERROR'
        end program test_read_stdin

Compiling the above simple program with gfortran or ifort I get:

$ ifort test_read_stdin.f -o test_read_stdin
$ echo -n "a" | ./test_read_stdin

as expected.

Instead, compiling with ifort the above command hangs and top shows very high CPU usage:

$ echo -n "a" | ./test_read_stdin
[1]+  Stopped                 echo -n "a" | ./test_read_stdin
$ bg
[1]+ echo -n "a" | ./test_read_stdin &
$ ps
  PID TTY          TIME CMD
 7841 pts/1    00:00:00 bash
19313 pts/1    00:00:02 test_read_stdin
19314 pts/1    00:00:00 ps
$ top -p 19313
top - 09:55:42 up 5 days, 56 min,  3 users,  load average: 0.80, 0.34, 0.12
Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.8%us,  4.8%sy,  0.0%ni, 94.3%id,  0.0%wa,  0.1%hi,  0.0%si,  0.0%st
Mem:   8058848k total,  6804384k used,  1254464k free,   336976k buffers
Swap:  6168572k total,   209088k used,  5959484k free,  5221952k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                                                                                           
19313 build     20   0 14028 1048  684 R 100.0  0.0   0:27.52 test_read_stdin                  

Is this intentional or is it a bug?

This change in behaviour may break a number of existing programs.

Thanks, kind regards

0 Kudos
1 Reply
1 View

Thank you for your report!

Thank you for your report! Please submit a bug report via our Online Service Center at  Our engineering team will investigate this further.

Instructions on how to file a ticket are available here:  

Devorah - Intel® Developer Support
0 Kudos