logo

How to Reference Device Names and Account Names in Julia 📂Julia

How to Reference Device Names and Account Names in Julia

Overview

Julia, aimed at high-performance computing, is likely to use multiple servers exceeding the usual level of computational demand. In such cases, it’s necessary to reference the unique name of each device for control, data transmission, or log creation.

Code

Device Name gethostname()

julia> gethostname()
"Sick3060"

A hostname is the name of a local machine. It can be used whenever the name of the server that provides resources, regardless of the connected user, is required1.

Username Sys.username()

From Julia version 1.11, the function Sys.username() is provided, eliminating the need to use different methods depending on the operating system as shown below.

Windows Account Name ENV["USERNAME"]

julia> Sys.iswindows()
true

julia> Sys.islinux()
false

julia> ENV["USERNAME"]
"rmsms"

In Windows, the account name can be referenced using ENV["USERNAME"].

julia> ENV["LOGNAME"]
ERROR: KeyError: key "LOGNAME" not found

Linux Account Name ENV["LOGNAME"]

julia> Sys.iswindows()
false

julia> Sys.islinux()
true

julia> ENV["LOGNAME"]
"rmsms"

In Linux, the account name can be referenced using ENV["LOGNAME"].

julia> ENV["USERNAME"]
ERROR: KeyError: key "USERNAME" not found

Environment

  • OS: Windows
  • julia: v1.11.0