Thread overview
kill and thisProcessID
Jun 24, 2015
Nordlöw
Jun 24, 2015
Per Nordlöw
Jun 24, 2015
Nordlöw
Jun 28, 2015
Nordlöw
Jun 24, 2015
nkpm
June 24, 2015
I have a process that shall suspend itself using SIGTSTP or SIGSTOP.

My current plan is

    import std.process: thisProcessID, kill, Pid;
    import core.sys.posix.signal: SIGKILL, SIGSTOP, SIGTSTP;
    const thisPid = thisProcessID;
    // some call to kill()

but kill() needs a `Pid`

so

    kill(thisPid, SIGTSTP);

fails and constructing Pid cannot be done because

    kill(new Pid(thisPid), SIGTSTP);

errors as

    Error: class std.process.Pid member this is not accessible

What to do?
June 24, 2015
On Wednesday, 24 June 2015 at 11:39:51 UTC, Nordlöw wrote:
> What to do?

See also: Discussion at http://dlang.org/library/std/process/kill.html
June 24, 2015
On Wednesday, 24 June 2015 at 11:39:51 UTC, Nordlöw wrote:
> What to do?

I believe the best solution is to add a new function

    Pid thisProcessPid()

to std.process and refer to this from kill(Pid). Should I do PR?
June 24, 2015
On 6/24/15 7:39 AM, "Nordlöw" wrote:
> I have a process that shall suspend itself using SIGTSTP or SIGSTOP.
>
> My current plan is
>
>      import std.process: thisProcessID, kill, Pid;
>      import core.sys.posix.signal: SIGKILL, SIGSTOP, SIGTSTP;
>      const thisPid = thisProcessID;
>      // some call to kill()
>
> but kill() needs a `Pid`
>
> so
>
>      kill(thisPid, SIGTSTP);
>
> fails and constructing Pid cannot be done because
>
>      kill(new Pid(thisPid), SIGTSTP);
>
> errors as
>
>      Error: class std.process.Pid member this is not accessible
>
> What to do?

Why not use core.sys.posix.signal: kill instead? You're already importing the module anyway.

-Steve

June 24, 2015
On Wednesday, 24 June 2015 at 11:39:51 UTC, Nordlöw wrote:
> I have a process that shall suspend itself using SIGTSTP or SIGSTOP.
>
> My current plan is
>
>     import std.process: thisProcessID, kill, Pid;
>     import core.sys.posix.signal: SIGKILL, SIGSTOP, SIGTSTP;
>     const thisPid = thisProcessID;
>     // some call to kill()
>
> but kill() needs a `Pid`
>
> so
>
>     kill(thisPid, SIGTSTP);
>
> fails and constructing Pid cannot be done because
>
>     kill(new Pid(thisPid), SIGTSTP);
>
> errors as
>
>     Error: class std.process.Pid member this is not accessible
>
> What to do?

in std.process, add a `kill()` overload that takes `thisPid` as argument, it will create the `Pid` as a local scoped instance and it will call the normal `kill()` version that takes a Pid as argument with the scoped `Pid` instance.
propose a PR for this overloaded `kill()` and wait dmd 2.068 release.

Pid is well locked BTW: private constructor, final class...
June 28, 2015
On Wednesday, 24 June 2015 at 11:58:37 UTC, Nordlöw wrote:
> I believe the best solution is to add a new function
>
>     Pid thisProcessPid()
>
> to std.process and refer to this from kill(Pid). Should I do PR?

PR at https://github.com/D-Programming-Language/phobos/pull/3448