Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: Joerg Schmitz-Linneweber Newsgroups: comp.os.linux.embedded Subject: Re: Reading /proc/stat btime from user space Date: Fri, 18 Jan 2013 16:41:10 +0100 Lines: 33 Message-ID: References: <2ddadfb4-bd08-4ffa-9153-a009b722eb56@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.dfncis.de 91v2PV1jVJ8mOtDVo+LSNw9HJpGgG4PELP3X6s8xnIBpOkdJsA7uKjXJXoJ/C0IHfTkiHO1gVo Cancel-Lock: sha1:daq93xCBO9cmHVuQNXYCRjvYCFM= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11 In-Reply-To: Xref: csiph.com comp.os.linux.embedded:438 Hi! Am 17.01.2013 23:20, schrieb SJC: > static void get_boottime(char *boottime) { > > FILE *fp; > int status; > > fp = popen("awk '/^btime/' /proc/stat", "r"); > if (fp == NULL) { > DEBUG("get_boottime: popen failed"); > } > else { > fgets(boottime, BOOTTIME_MAX_LEN, fp); > DEBUG("get_boottime: Boottime is %s", boottime); > status = pclose(fp); > if (status == -1) { > DEBUG("get_boottime: Could not close"); > } > } > return; > } You're kidding, aren't you? :-) Why not read in the file line-by-line and check if the actual line starts with 'btime'? (fopen, fgets, strncmp, fclose) You are starting a new process and creating two pipes to read something from a (text) file? Perhaps Tauno's tip was more suitable... ;-) Salut, Jörg