Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
May 18, 2020 None of the overloads of kill are callable using argument types: | ||||
---|---|---|---|---|
| ||||
I'm trying to kill my own process, but I'm being unsuccessful at the compilation of the program. It seems that neither getpid nor thisProcessID returns a correct type value for the kill function. HelloWorld.d(24): Error: none of the overloads of kill are callable using argument types (int), candidates are: C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2327): std.process.kill(Pid pid) C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2338): std.process.kill(Pid pid, int codeOrSignal) HelloWorld.d import std.stdio : write, writeln, readln, writefln; import std.process : executeShell, kill, thisProcessID; import core.thread.osthread : getpid; void main() { executeShell("title HelloWorld"); executeShell("chcp 65001"); writeln("Hello, World!"); writeln(" ▄ .▄▄▄▄ .▄▄▌ ▄▄▌ ▄▄▌ ▐ ▄▌ ▄▄▄ ▄▄▌ ·▄▄▄▄ ██▪▐█▀▄.▀·██• ██• ▪ ██· █▌▐█▪ ▀▄ █·██• ██▪ ██ ██▀▐█▐▀▀▪▄██▪ ██▪ ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪ ▐█· ▐█▌ ██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌ ▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██ ▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀ ▀█▄▀▪ ▀▀▀▀ ▀▪ ▀█▄▀▪.▀ ▀.▀▀▀ ▀▀▀▀▀• "); writefln("Current process id: %s", getpid()); writeln("This process id: ", thisProcessID()); string line; write("Your Input: "); while ((line = readln()) !is null) { writeln(line); kill(thisProcessID()); write("Your Input: "); } } |
May 18, 2020 Re: None of the overloads of kill are callable using argument types: | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | On Monday, 18 May 2020 at 20:11:25 UTC, BoQsc wrote:
> I'm trying to kill my own process
Don't kill yourself, just `return` from main.
|
May 18, 2020 Re: None of the overloads of kill are callable using argument types: | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | On 5/18/20 1:11 PM, BoQsc wrote:> I'm trying to kill my own process, but I'm being unsuccessful at the > compilation of the program. It seems that neither getpid nor > thisProcessID returns a correct type value for the kill function. Of course, Adam D. Ruppe is right: You can simply return from main() in this case. Or, Pid is given to you for processes that you've spawned. Your question brings one of my recent pet peeves in software: the 'private' keyword.[1] In this case, it's Pid's constructor. I wanted to do the following but it failed because the constructor is private: auto p = new Pid(thisProcessID()); Ali [1] I don't think 'private' keyword ever protected me. I'm pretty sure of it because if I've ever reached for undocumented features of a type or if I've ever used any member, say, having a name starting with '_', I would be sure to be punished in the future if the implementation changed. I know that and I'm sure it's very easy to teach it to beginners. It's too much protecting me from myself. On the other hand, there have been multiple cases where 'private' keyword was hiding a useful feature: D runtime's GC statistics (at least in the past), some of std.getopt's parsing functions, etc. Note to self: Think twice before making anything 'private'. |
May 19, 2020 Re: None of the overloads of kill are callable using argument types: | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 18 May 2020 at 20:40:47 UTC, Adam D. Ruppe wrote: > On Monday, 18 May 2020 at 20:11:25 UTC, BoQsc wrote: >> I'm trying to kill my own process > > Don't kill yourself, just `return` from main. Returning does what I need, however I still need to get a working example on killing/terminating for the future reference, just in case. However as Ali Çehreli stated, there seems to be a bigger problem, to why it is not possible right now. import std.stdio : write, writeln, readln, writefln; import std.process : spawnShell, wait, executeShell, kill, thisProcessID; import core.thread.osthread : getpid; void main() { spawnShell( "cls" ).wait; executeShell("title HelloWorld"); executeShell("chcp 65001"); executeShell("mode con: cols=120 lines=30"); writeln("Hello, World!"); writeln(" ▄ .▄▄▄▄ .▄▄▌ ▄▄▌ ▄▄▌ ▐ ▄▌ ▄▄▄ ▄▄▌ ·▄▄▄▄ ██▪▐█▀▄.▀·██• ██• ▪ ██· █▌▐█▪ ▀▄ █·██• ██▪ ██ ██▀▐█▐▀▀▪▄██▪ ██▪ ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪ ▐█· ▐█▌ ██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌ ▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██ ▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀ ▀█▄▀▪ ▀▀▀▀ ▀▪ ▀█▄▀▪.▀ ▀.▀▀▀ ▀▀▀▀▀• A Tale of HelloWorld"); writeln(" ┌──------------┐ ▒░░░┼┼┼┼┼┐ ≡▒░ ¦ ___▒▒▒▒▒▒┼┤┼▒▒▒▒▒▒▓"); writeln(" ~¨(··)¸ <│ > ‗┌═¬‗´ "); writefln("Current process id: %s", getpid()); writeln("This process id: ", thisProcessID()); string line; write("Your Input: "); while ((line = readln()) !is null) { if (line == "exit\x0a") { writeln("Going down"); return; } write(line); write("Your Input: "); } } |
May 19, 2020 Re: None of the overloads of kill are callable using argument types: | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On 5/18/20 9:18 PM, Ali Çehreli wrote: > On 5/18/20 1:11 PM, BoQsc wrote:> I'm trying to kill my own process, but I'm being unsuccessful at the > > compilation of the program. It seems that neither getpid nor > > thisProcessID returns a correct type value for the kill function. > > Of course, Adam D. Ruppe is right: You can simply return from main() in this case. Or, Pid is given to you for processes that you've spawned. > > Your question brings one of my recent pet peeves in software: the 'private' keyword.[1] In this case, it's Pid's constructor. I wanted to do the following but it failed because the constructor is private: > > auto p = new Pid(thisProcessID()); This is not a problem with private, but with the choice of the library designer. Being able to define how things are created enables semantic guarantees that cannot be enforced if you don't protect data. Encapsulation is not a bad thing, but could possibly be misapplied. In this case, Pid is simply a wrapper around an int or a HANDLE. I'm not seeing the purpose to prevent someone from constructing pids from ints or native OS handles. So maybe it's something that can be added. > > Ali > > [1] I don't think 'private' keyword ever protected me. I'm pretty sure of it because if I've ever reached for undocumented features of a type or if I've ever used any member, say, having a name starting with '_', I would be sure to be punished in the future if the implementation changed. I know that and I'm sure it's very easy to teach it to beginners. It's too much protecting me from myself. > > On the other hand, there have been multiple cases where 'private' keyword was hiding a useful feature: D runtime's GC statistics (at least in the past), some of std.getopt's parsing functions, etc. Note to self: Think twice before making anything 'private'. > There have been things that were undocumented that we wanted to change in phobos, but we had to go through a long deprecation cycle because they weren't marked private and changing the name broke some code of people who noticed the symbol and used it. So no, it's not a guarantee that just not documenting something or naming it badly is going to prevent you from having it be considered public API. -Steve |
Copyright © 1999-2021 by the D Language Foundation