/* *libproc * *A library interface for finding process information from /proc. *This is also an interface into various things which haven't yet been integrated into sysfs, * as appropriate. Copyright (C) 2004 Joseph Pingenot This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "libproc.h" #define LOADAVG_FILE "/proc/loadavg" #define LIBPROC_ERRLEN 1024 struct libproc_loadavg *libproc_getloadavg() { FILE *file; char errstring[LIBPROC_ERRLEN]; int err; struct libproc_loadavg *la; file = fopen(LOADAVG_FILE, "r"); if(file == NULL){ err=errno; if(strerror_r(err, errstring, LIBPROC_ERRLEN)){ fprintf(stderr, "libproc: unable to open loadavg file (%s) file (error %s)\n", LOADAVG_FILE, errstring); }else{ fprintf(stderr, "libproc: unable to open loadavg file (%s) file (error %d)\n", LOADAVG_FILE, err); } return NULL; } if((la = (struct libproc_loadavg*)malloc(sizeof(struct libproc_loadavg))) == NULL){ fprintf(stderr, "libproc: unable to allocate memory for loadavg struct!\n"); return NULL; } /*Alright; the file's open and we have RAM for it. Snag the info.*/ err = fscanf(file, "%f%f%f%lu/%lu%lu", &(la->one), &(la->two), &(la->three), &(la->running), &(la->total), &(la->lastproc)); if(err != 6){ fprintf(stderr, "libproc: format in loadavg file (%s) unrecognized!\n", LOADAVG_FILE); free(la); return NULL; } fclose(file); return la; } void libproc_destroy_loadavg(struct libproc_loadavg *la) { free(la); } struct libproc_status *libproc_getstatus(pid_t pid) { FILE *file; char errstring[LIBPROC_ERRLEN]; int err; void *handle; if( char *name; char state; short int sleepavg; gid_t tgid; pid_t pid; pid_t ppid; pid_t tracer; uid_t uid0; uid_t uid1; uid_t uid2; uid_t uid3; gid_t gid0; gid_t gid1; gid_t gid2; gid_t gid3; int fdsize; struct libproc_group *groups; long int vmsize; long int vmlck; long int vmrss; long int vmdata; long int vmstck; long int vmexe; long int vmlib; long int threads; long int sigpnd; long int shdpnd; long int sigblk; long int sigign; long int sigcgt; long int capinh; long int capprm; long int capeff; };