LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   about /proc/$pid/stat 's start time (https://www.linuxquestions.org/questions/programming-9/about-proc-%24pid-stat-s-start-time-195226/)

henryluo 06-19-2004 01:45 AM

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

murugesan 06-21-2004 06:48 AM

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


henryluo 06-21-2004 09:15 AM

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


All times are GMT -5. The time now is 12:10 AM.