Browse thread
Writing to argv[0]
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Dave Benjamin <dave@r...> |
| Subject: | Re: [Caml-list] Writing to argv[0] |
Dave Benjamin wrote:
> Basile STARYNKEVITCH wrote:
>> Write a C wrapper for that. And this trick seems Linux specific (it
>> has no sense in Posix) -maybe working on few other OSes.
>
> It doesn't seem like it's possible, even if I drop to C. Writing to
> "caml_exe_name" does nothing, and "caml_main_argv" is declared static.
Just as I was about to give up, I found this thread, which alerted me to
GNU's "program_invocation_name" global:
http://groups.google.com/group/comp.unix.programmer/browse_thread/thread/99acb4dff3707e56/003e46ff836f5d9e
So, I finally got it to work in OCaml. This is GNU/Linux only, most likely.
proctitle.idl:
quote(c, "extern char * program_invocation_name;");
[string] char * getproctitle(void)
quote(call, "_res = program_invocation_name;");
void setproctitle([string] char * proctitle)
quote(call, "strcpy(program_invocation_name, proctitle);");
test.ml:
let () =
Proctitle.setproctitle "testing setproctitle";
print_endline (Proctitle.getproctitle ());
Unix.sleep 10