Porfuncs Documentation

From Docswiki
Jump to navigation Jump to search

Various system functions are included in the porfuncs module, generated from porfuncs.sh. They are documented here as a reference for developers. Please use these subroutines, rather than any of the system calls directly, to maintain compiler independence.

FLUSH

subroutine flush(unit, istat)
  integer, intent(in) :: unit
  integer, intent(out), optional :: istat

Flushes the output buffer of the stream specified by unit. The optional argument istat does nothing and is present to allow old code to compile. It should be omitted from new code.

IARGC

subroutine iargc_subr(n)
  integer, intent(out) :: n

Sets n to be the number of command line arguments which were present when the program was invoked.

GETARG

subroutine getarg_subr(position, value)
  integer, intent(in) :: position
  character(len=*), intent(out) :: value

Sets value to be the command line argument specified by position.

FORK

subroutine fork_subr(pid)
  integer, intent(inout) :: pid

Creates a copy of the current process, with the copy being a child of the current process. In the parent process, pid is set to the process ID of the child process. In the child process, pid is set to zero.

SYSTEM

subroutine system_subr(jobstring, exitstatus)
  character(len=*), intent(in) :: jobstring
  integer, intent(out), optional :: exitstatus

Execute the command present in jobstring. If the optional argument exitstatus is present, it will be set to the return value of the command.

WAIT

subroutine wait_subr(pid, exitstatus)
  integer, intent(inout) :: pid
  integer, intent(inout) :: exitstatus

Suspend execution of the current process until one of its child processes exits. pid is set to the process ID of the exiting process. exitstatus is set to the return value of the child process.

GETPID

subroutine getpid_subr(pid)
  integer, intent(out) :: pid

Set pid to the process ID of the current process.

EXIT

subroutine exit_subr(exitstatus)
  integer, intent(in) :: exitstatus

Terminate the current process, with the return value specified by exitstatus.