From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA27398; Tue, 21 Jan 2003 21:53:17 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA27187 for ; Tue, 21 Jan 2003 21:53:16 +0100 (MET) Received: from mallaury.noc.nerim.net (smtp-102.noc.nerim.net [62.4.17.102]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h0LKrFv08639 for ; Tue, 21 Jan 2003 21:53:15 +0100 (MET) Received: from hector.lesours (lesours.starynkevitch.net [80.65.224.217]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 7610362DE4; Tue, 21 Jan 2003 21:53:12 +0100 (CET) Received: from basile by hector.lesours with local (Exim 3.36 #1 (Debian)) id 18b5OU-0007vA-00; Tue, 21 Jan 2003 21:53:14 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <15917.45880.856573.222243@hector.lesours> Date: Tue, 21 Jan 2003 21:53:12 +0100 To: Issac Trotts Cc: caml-list@inria.fr Subject: Re: [Caml-list] uname for Ocaml In-Reply-To: <20030121202955.GA5938@beech> References: <15917.26071.995917.528195@hector.lesours> <20030121202955.GA5938@beech> X-Mailer: VM 7.07 under Emacs 21.2.2 From: Basile STARYNKEVITCH Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Issac cited me after his reply - I put it in the right order. >>>>> "Issac" == Issac Trotts writes: Issac> On Tue, Jan 21, 2003 at 04:23:03PM +0100, Basile Issac> STARYNKEVITCH wrote: >> Dear All, >> >> If you need to call uname(2) from some Ocaml program you can >> steal my tiny code in util.ml util.mli util_ml.c on >> >> http://www2.poesia-filter.org:8000/cgi-bin/cvsweb.cgi/PoesiaSoft/PoesiaMonIcap/ >> >> I actually wish that uname(2) will be incorporated in the Unix >> module. >> Issac> An alternative would be to use #load "unix.cma" I agree with Issac, but I still wish that most (or perhaps all) of the standard Posix system calls should be callable from Unix module! Issac> let uname() = let (inc, outc) = Unix.open_process "uname" Issac> in let name = input_line inc in close_in inc; close_out Issac> outc; name;; Won't work if the (malicious) user have an unrelated uname in his path. I suggest at least using the "/bin/uname" which should be a POSIX standard IIRC. Also, forking a shell process for each system call might be not optimal (and not robust). Also, my code return the equivalent of /bin/uname -a Issac> Here's a more general way to capture the stdout of a Unix Issac> call: Issac> let syscall cmd = let (inc, outc) = Unix.open_process cmd Issac> in let buf = Buffer.create 16 in (try while true do Issac> Buffer.add_channel buf inc 1 done with _ -> ()); close_in Issac> inc; close_out outc; Buffer.contents buf;; Thanks for this suggestion, but why not use Unix.open_process_in in this and similar cases? On a related, but independent, issue, Linux hackers might be interested in the procfs.ml[i] files from http://www2.poesia-filter.org:8000/cgi-bin/cvsweb.cgi/PoesiaSoft/PoesiaMonIcap/ The idea is to get the status of a process by parsing /proc/#/stat into an intelligible structure. This is Linux specific (works on linux 2.4 & 2.5 kernels). The code is mostly a huge (and boring) scanf, using a format stolen from the linux kernel (see comments in procfs.ml). Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet alias: basiletunesorg 8, rue de la Faïencerie, 92340 Bourg La Reine, France ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners