If I run a Java process as background service then System.getProperty("user.name")
returns ever the hostname with an additional $ character.
Is there a solution to get the real user name of the process which I can see in the Windows task manager?
You can obtain the user who owns the current Java process using ProcessHandle.current().info().user().get()
. It should be the same information provided by the system's task list.
The documentation for ProcessHandle is here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.