linux - 命名管道和 Fortran 的问题

标签 linux fortran named-pipes gfortran

我尝试通过命名管道在某些 Fortran 进程之间建立通信。然而,考虑到即使是一个非常简单的玩具示例,我也会遇到麻烦。这是我的代码:

  program testfifo

  implicit none

  integer status

  write(*,*) "hello"
  call flush()

  open(unit=11,file="MyNamedPipe",action='write',form ='unformatted'
 $     ,iostat=status);
  close(11)

  write(*,*) "by"
  call flush()

  return
  end program testfifo    

如果我用普通文件运行它,它会工作:

/fortran > rm -f MyNamedPipe && touch MyNamedPipe
/fortran > gfortran -o testfifo testfifo.f 
/fortran > ./testfifo 
 hello
 by

但是,使用 fifo 运行我的程序会卡住:

/fortran > rm -f MyNamedPipe && mkfifo MyNamedPipe
/fortran > gfortran -o testfifo testfifo.f 
/fortran > ./testfifo 
 hello
^C

我没有收到任何错误消息。此外,我尝试将 open 语句格式化为 <-> 未格式化,使用 err=100 进行错误处理等,但没有帮助。以下是我的一些系统统计信息:

Linux lin45 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
gfortran 4.6.2
海合会 4.6.2
g++ 4.6.2

我在网上搜索这个问题的解决方案已经有一段时间了。如果有人能帮助我,我会很高兴。另外,如果有人能够毫无问题地运行代码,我很想知道这是否可能是由于任何系统/编译器问题造成的。谢谢。

注意:我真正感兴趣的程序需要在#n 个进程之间进行通信,因此,我认为,我不能使用普通管道。此外,已经有一个使用管道设置的代码版本。但是,它只能在 Mac 上运行。我的任务是在 Linux 下运行它。 Mac 规范为:

Mac OS X 10.7.5
Xcode 4.5
gfortran 4.6.1
海合会 4.2.1
g++ 4.2.1

最佳答案

这对我有用。不知何故,action="write" 有问题。

    program testfifo

    implicit none

    integer status

    write(*,*) "hello"
    call flush()

    open(unit=11,file="MyNamedPipe",access='stream'                    &
 &   ,form ='unformatted', iostat=status)
    write(11) status
    print *, status
    close(11)

    write(*,*) "by"
    call flush()

    end program testfifo  

因为 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30162,我使用了 stream 访问

关于linux - 命名管道和 Fortran 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22074763/

相关文章:

ruby - 在 Linux 上使用 skript 同步两个目录的特殊类型

c++ - 如何编译gtest cpp文件?

c - 从 C 作为结构体访问 Fortran 公共(public) block

arrays - 数组维度的排序

compiler-errors - Fortran90 未分类语句 While 循环

c++ - windows:是否可以将文本文件转储(直接)到命名管道中

c - 删除换行符

python - 在 ubuntu 18.04 安装 spyder-vim

linux - 在 if 语句中使用 grep

Python 和 Windows 命名管道