English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Writing to argv[0]
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-10-10 (13:27)
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:


So, I finally got it to work in OCaml. This is GNU/Linux only, most likely.


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);");


let () =
   Proctitle.setproctitle "testing setproctitle";
   print_endline (Proctitle.getproctitle ());
   Unix.sleep 10