Lua4z
A binary distribution of Lua for z/OS, with batteries
-- Print the path of the Lua interpreter running this program

posix = require("posix")
stringx = require("pl.stringx")

-- Returns output from system command, trimmed
function system(cmd)
  local f
  -- Call to io.popen will fail if not running in POSIX environment
  -- (for example, MVS)
  local ok = pcall(
    function ()
      f = assert(io.popen(cmd, "r"))
    end
  )
  if ok then
    local s = assert(f:read("*a"))
    f:close()
    return stringx.strip(s)
  else
    return nil
  end
end

-- Get the process ID of the current process
-- (the Lua interpreter that is running this Lua program)
local pid = posix.getpid("pid")

-- Get the path ("command") of the executable program
-- for this process
local path = system("ps -o comm= -p " .. pid)

if path then
  -- Is the path a symlink?
  local symlink = posix.readlink(path)
  if symlink then
    print("Path (a symlink): " .. path)
    print("Symlink refers to: " .. symlink)
  else
    print("Path (actual file, not a symlink): " .. path)
  end
else
  print("Cannot determine path: are you running Lua on MVS in non-POSIX mode?")
end