Talvez você possa ver o cmdline
ou exe
associado ao PID:
# stat /proc/2529/{exe,cmdline}
File: ‘/proc/2529/exe’ -> ‘/bin/bash’
Size: 0 Blocks: 0 IO Block: 1024 symbolic link
Device: 3h/3d Inode: 16136 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-09-26 07:46:05.435479000 +0530
Modify: 2014-09-26 07:41:05.447479000 +0530
Change: 2014-09-26 07:41:05.447479000 +0530
Birth: -
File: ‘/proc/2529/cmdline’
Size: 0 Blocks: 0 IO Block: 1024 regular empty file
Device: 3h/3d Inode: 16117 Links: 1
Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-09-26 07:41:05.447479000 +0530
Modify: 2014-09-26 07:41:05.447479000 +0530
Change: 2014-09-26 07:41:05.447479000 +0530
Birth: -
Eu usei o comando stat
, mas não o faço Acho que a função stat
responderia de forma diferente quando aplicada a esses arquivos.
Um exemplo:
Salvar como test.c
:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main(int argc, char *argv[])
{
struct stat stats;
char exe_path[32] = "/proc/";
char cmdline_path[32] = "/proc/";
char *exe = "/exe", *cmdline = "/cmdline";
if (argc < 2)
return -1;
if (lstat (strcat (strcat (exe_path, argv[1]), exe), &stats) != -1)
{
printf("exe: %s\n%s%s%s", exe_path, ctime (&stats.st_atime), ctime (&stats.st_mtime), ctime (&stats.st_ctime));
}
else perror ("stat error: ");
if (lstat (strcat (strcat (cmdline_path, argv[1]), cmdline), &stats) != -1)
{
printf("cmdline: %s\n%s%s%s\n", cmdline_path, ctime (&stats.st_atime), ctime (&stats.st_mtime), ctime (&stats.st_ctime));
}
else perror ("stat error: ");
return 0;
}
Teste:
$ gcc -o test test.c
$ ./test $$
exe: /proc/1811/exe
Fri Sep 26 09:02:59 2014
Fri Sep 26 09:02:59 2014
Fri Sep 26 09:02:59 2014
cmdline: /proc/1811/cmdline
Fri Sep 26 09:02:59 2014
Fri Sep 26 09:02:59 2014
Fri Sep 26 09:02:59 2014
$ date
Fri Sep 26 09:34:03 IST 2014
As estatísticas de cmd
talvez sejam mais confiáveis.