LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-19-2004, 01:45 AM   #1
henryluo
Member
 
Registered: Nov 2003
Posts: 36

Rep: Reputation: 15
about /proc/$pid/stat 's start time


hi all:

i have a problem about the stat file, i find the book say the stat file contain the start time, but how transform it to normarl datetime(2004-05-12 10:00),thanks
 
Old 06-21-2004, 06:48 AM   #2
murugesan
Member
 
Registered: May 2003
Posts: 149

Rep: Reputation: 28
This will do.

Code:
void print_time(int pid)
{
        static int ppid;
        unsigned long time;
        char ch;
        char buffer[256];
        FILE *f;
        sprintf(buffer,"/proc/%d/stat",pid);
        if (!(f = fopen(buffer,"rt")))
                return ;
        fscanf(f,"%*d %*s %*c %lu",&ppid,buffer,&ch,&time);
        printf("%s\n",ctime(time));
        fclose(f);
}

Last edited by murugesan; 06-21-2004 at 06:49 AM.
 
Old 06-21-2004, 09:15 AM   #3
henryluo
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Code:
#include <stdio.h>
#include <time.h>

void print_time(int pid)
{
        static int ppid;
        unsigned long time;
        char ch;
        char buffer[256];
        FILE *f;
        sprintf(buffer,"/proc/%d/stat",pid);
        if (!(f = fopen(buffer,"rt")))
                return ;
        fscanf(f,"%*d %*s %*c %lu",&ppid,buffer,&ch,&time);
        printf("%s\n",ctime(time));
        fclose(f);
}



main()
{
        int pid=3965;
        print_time(pid);
}
the run result:
[root@server2 root]# ./a.out
Wed Oct 3 23:48:59 2007


what wrong about this;
as the same time i use this command'result is this
[root@server2 root]# ps -aux|grep 3965
root 3965 0.0 0.3 4292 860 ? S Jun17 0:03 /bin/bash /surebet/bin/checktimeout.sh
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/proc/stat values don't add up ! mike0w Linux - General 0 10-25-2005 05:01 AM
New cpu values in /proc/stat? eldonz Linux - General 1 10-19-2005 12:16 PM
/proc/stat cpu info GDarkBladE Linux - Software 2 10-11-2005 03:16 PM
/proc/stat cpu ahz Programming 1 04-24-2005 07:24 AM
How reliable is /proc/stat information vs LTT ? rbarara Linux - Software 0 11-25-2004 09:07 PM


All times are GMT -5. The time now is 09:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration