blob: a0cba0512c87e6a5313d62eba611d0bfd34057bf [file] [log] [blame] [raw]
/* libprocstat
Copyright 2015-2022 Rivoreo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program 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
General Public License for more details.
*/
#ifndef _PROCSTAT_H
#define _PROCSTAT_H
#include <sys/types.h>
#include <stdint.h>
#define PROC_STAT_COMM_MAX_LENGTH 16
struct procstat_handle;
struct procstat {
pid_t pid;
pid_t ppid;
pid_t pgid;
pid_t tpgid;
pid_t sid;
pid_t tsid;
pid_t tgid; // Linux-specific
dev_t tty;
uid_t ruid;
uid_t euid;
gid_t rgid;
gid_t egid;
size_t size;
size_t rssize;
uintptr_t wchan;
uintptr_t ip;
int is_kernel_process;
#if 0
uint64_t user_time;
uint64_t kernel_time;
uint64_t child_user_time;
uint64_t child_kernel_time;
#else
uint64_t time;
uint64_t child_time;
#endif
uint64_t start_time;
int num_threads;
char state;
int on_psr;
long int priority; // Platform-dependent
signed char nice; // Platform-dependent
unsigned int rt_priority; // Platform-dependent
unsigned int sched_class; // Platform-dependent
char comm[PROC_STAT_COMM_MAX_LENGTH];
//char command_line[0];
};
#define PROCSTAT_MAIN_THREAD_INFO (1 << 0)
#define PROCSTAT_WALK_ALL 0 /* May containing thread information on Linux */
#define PROCSTAT_WALK_THREADS 1
#define PROCSTAT_WALK_KERNEL 2
#define PROCSTAT_WALK_USER 3
struct procstat_handle *procstat_open(void);
void procstat_close(struct procstat_handle *);
int procstat_get(struct procstat_handle *, pid_t, int, struct procstat *);
int procstat_get_command_line(struct procstat_handle *, pid_t, char **);
int procstat_get_argv(struct procstat_handle *, pid_t, int *, char ***);
int procstat_get_path(struct procstat_handle *, pid_t, char **);
int procstat_get_mac_label(struct procstat_handle *, pid_t, char **);
void procstat_walk(struct procstat_handle *, int, int, int (*)(struct procstat_handle *, struct procstat *, void *), void *);
#endif