/home/fernape/Projects/lkmonitor/src/procinfo.c File Reference

#include <gnome.h>
#include <dirent.h>
#include <errno.h>
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "lkmonitor.h"
#include "others.h"
#include "procinfo.h"
#include "update.h"

Go to the source code of this file.

Defines

#define UNK_STR   _("Unknown")

Functions

int get_mm_details (const int pid, struct mm_details *details, const char *mmregion)
 Get memory region details.
int get_process_info (const int pid, struct procinfo *pi, struct dirent ***file_list, int *numfiles)
 Gets process information.


Define Documentation

#define UNK_STR   _("Unknown")

Definition at line 44 of file procinfo.c.

Referenced by get_mm_details(), and update_fd_info().


Function Documentation

int get_mm_details ( const int  pid,
struct mm_details details,
const char *  mmregion 
)

Get memory region details.

Get memory region details for a process

Parameters:
pid The PID of the process
details mm_details structure pointer
mmregion Region we want details about
Returns:
0 on success, -1 otherwise

Definition at line 312 of file procinfo.c.

References DEF_SZ, find_data_for(), mm_details::priv_clean, mm_details::priv_dirty, mm_details::rss, mm_details::sh_clean, mm_details::sh_dirty, mm_details::size, and UNK_STR.

Referenced by update_mm_details().

00314 {
00315         g_assert(pid>0 && details!=NULL && mmregion!=NULL);
00316 
00317         /* We use mmregion to make the search */
00318         GString *smaps_file=g_string_new("");
00319         gchar *contents;
00320         char *p;
00321 
00322         /* Construct the path */
00323         g_string_printf(smaps_file,"/proc/%d/smaps",pid);
00324 
00325         if((g_file_get_contents(smaps_file->str,&contents,NULL,NULL))==FALSE){
00326                 /* Something wrong with the file... 
00327                  * So put default values
00328                 */
00329                 strncpy(details->size,UNK_STR,DEF_SZ);
00330                 strncpy(details->rss,UNK_STR,DEF_SZ);
00331                 strncpy(details->sh_clean,UNK_STR,DEF_SZ);
00332                 strncpy(details->sh_dirty,UNK_STR,DEF_SZ);
00333                 strncpy(details->priv_clean,UNK_STR,DEF_SZ);
00334                 strncpy(details->priv_dirty,UNK_STR,DEF_SZ);
00335                 
00336                 /* Cleaning up */
00337                 g_string_free(smaps_file,TRUE);
00338                 g_free(contents);
00339 
00340                 return -1;
00341         }
00342 
00343         /* OK, the file is in the buffer */
00344 
00345         if ((p=strstr(contents,mmregion))!=NULL){
00346                 /* Use the find_data_for function again */      
00347                 find_data_for("Size: %[^\n]",details->size,p);
00348                 find_data_for("Rss: %[^\n]",details->rss,p);
00349                 find_data_for("Shared_Clean: %[^\n]",details->sh_clean,p);
00350                 find_data_for("Shared_Dirty: %[^\n]",details->sh_dirty,p);
00351                 find_data_for("Private_Clean: %[^\n]",details->priv_clean,p);
00352                 find_data_for("Private_Dirty: %[^\n]",details->priv_dirty,p);
00353         }
00354 
00355         /* Clean up ... */
00356 
00357         g_string_free(smaps_file,TRUE);
00358 
00359         return 0;
00360 }

int get_process_info ( const int  pid,
struct procinfo pi,
struct dirent ***  file_list,
int *  numfiles 
)

Gets process information.

Get wide process information by calling auxiliary functions

Parameters:
pid The PID of the process
pi procinfo structure pointer
file_list dirent structure triple pointer
numfiles number of opened files by the process (output parameter)
Returns:
0 on success, -1 otherwise

Definition at line 369 of file procinfo.c.

References lkmonitor_itoa().

Referenced by update_process_window().

00371 {
00372         g_assert(pid>0 && pi!=NULL);
00373 
00374   GString *path=g_string_new("/proc/");
00375 
00376   g_string_append(path,(gchar *)lkmonitor_itoa(pid));
00377 
00378   /* Get cmdline info */
00379   if(get_cmdline_info(path->str,pi)!=0)
00380         g_warning("Can't get cmdline info.");
00381 
00382   /* Get environment info */
00383   if(get_env_info(path->str,pi)!=0)
00384         g_warning("Can't get environment info for process");
00385  
00386   /* Get maps info */
00387   if(get_maps_info(path->str,pi)!=0)
00388         g_warning("Can't get memory maps info.");
00389 
00390   /* Get files info */
00391   if(get_files_info(path->str,pi,file_list,numfiles)!=0)
00392         g_warning("Can't get file descriptors info.");
00393 
00394         /* Get VM info and other status file information */
00395         if(get_vm_info(path->str,pi)!=0)
00396                 g_warning("Can't get VM info.");
00397 
00398   /* Cleaning up... */
00399   g_string_free(path,TRUE);
00400   
00401   return 0;
00402 }


Generated on Tue Apr 1 22:52:56 2008 for lkmonitor by  doxygen 1.5.1