const main args?
Dan Olson
zans.is.for.cans at yahoo.com
Sat Aug 20 00:05:36 PDT 2011
mimocrocodil <4denizzz at gmail.com> writes:
> I seen what sendmail actually changes they arguments of command line for nice output of "ps ax" command.
>
> May be it changes his argc/argv for this?
Yes. Some unix C programs, daemons usually, modify argv to change what ps shows. It works with D too, I tried it (but have to cast away immutable). Here is a quick demo, assuming args[0] has enough room.
import std.c.string;
import core.thread;
void main(string[] args)
{
auto a = cast(char*)args[0].ptr;
strcpy(a, "xyzzy"); // change ps output to list us as xyzzy
Thread.sleep(dur!("seconds")(10));
}
$ ps
PID TTY TIME CMD
355 ttys000 0:00.01 /bin/bash --noediting -i
358 ttys000 0:00.00 xyzzy
Since you have to be unsafe anyway, casting to char* from in string would be no worse than string.
More information about the Digitalmars-d-learn
mailing list