yutotakano · GitHub

Change

This PR adds a new exported function in System.Process: getCurrentPid.

This calls getCurrentProcessId from System.Win32.Process on Windows, and getProcessID from System.Posix.Process on POSIX systems.

Rationale

This seems like an oversight considering getPid is implemented already. I sometimes require the current running program's process ID. Currently, I have to do the CPP conditional logic myself every time, which is a pain. Putting this in process seems natural.

Furthermore, my understanding of process is that it is a unified interface to System.Win32.Process and System.Posix.Process. As both modules provide a function to "get the currently executing process id", I feel it makes sense to have a cross-platform wrapper function.

Remaining Issues

The @since field has been left as a TODO since I'm not sure what version this will be merged in.

Tests

I could not come up with a method to test the PR. Unlike with the test for getPid, there's nothing to compare the value against, I think. It's worked from my past experiences in personal projects.

I wasn't able to ensure a stable setup to test to begin with, as running the existing test suite stack test on the Windows version of Stack failed due to several reasons (getPid failing, and detatch_console failing). Any feedback or insight is therefore appreciated.

Read the original on github.com ↗