process.h
/*
* libsysactivity
* http://sourceforge.net/projects/libsysactivity/
* Copyright (c) 2009, 2010 Carlos Olmedo Escobar <carlos.olmedo.e@gmail.com>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SA_PROCESS_H_
#define SA_PROCESS_H_
#include <sys/types.h>
enum sa_process_state {
SA_UNKNOWN = 0,
SA_RUNNING = 1,
SA_SLEEPING = 2,
SA_SLEEPING_UNINTERRUPTIBLE = 3,
SA_ZOMBIE = 4,
SA_STOPPED = 5,
};
struct sa_process_activity {
#ifdef SA_PROCESS_PID
pid_t pid;
#endif
#ifdef SA_PROCESS_STATE
enum sa_process_state state;
#endif
#ifdef SA_PROCESS_USER_TIME // TODO Explain these better
uint64_t user_time;
#endif
#ifdef SA_PROCESS_SYS_TIME
uint64_t sys_time;
#endif
#ifdef SA_PROCESS_THREADS
uint32_t threads;
#endif
#ifdef SA_PROCESS_VM_SIZE
uint32_t vm_size;
#endif
#ifdef SA_PROCESS_RSS
uint32_t rss;
#endif
};
struct sa_process {
#ifdef SA_PROCESS_PID
pid_t pid;
#endif
#ifdef SA_PROCESS_UID
uid_t uid;
#endif
#ifdef SA_PROCESS_GID
gid_t gid;
#endif
#ifdef SA_PROCESS_FILENAME
char filename[SA_PROCESS_FILENAME];
#endif
#ifdef SA_PROCESS_CMDLINE
char cmdline[SA_PROCESS_CMDLINE];
#endif
#ifdef SA_PROCESS_PARENT_PID
pid_t parent_pid;
#endif
#ifdef SA_PROCESS_PGRP
pid_t pgrp;
#endif
#ifdef SA_PROCESS_SID
pid_t sid;
#endif
#ifdef SA_PROCESS_TTY
pid_t tty;
#endif
#ifdef SA_PROCESS_NICE
int8_t nice;
#endif
#ifdef SA_PROCESS_START_TIME
uint64_t start_time;
#endif
struct sa_process_activity activity;
};
#ifdef SA_OPEN_PROCESS
int sa_open_process() SA_EXPORT;
#endif
#ifdef SA_CLOSE_PROCESS
int sa_close_process() SA_EXPORT;
#endif
int sa_count_processes(uint32_t* number) SA_EXPORT SA_NONNULL;
int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) SA_EXPORT SA_NONNULL;
int sa_get_process(pid_t pid, struct sa_process* dst) SA_EXPORT SA_NONNULL;
int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) SA_EXPORT SA_NONNULL;
#endif /* SA_PROCESS_H_ */
sa_get_process
int sa_get_process(pid_t pid, struct sa_process *dst) SA_EXPORT SA_NONNULL
sa_process_state
sa_process_state
Definition: process.h:33
sa_process::pgrp
pid_t pgrp
The group id the process.
Definition: process.h:92
sa_count_processes
int sa_count_processes(uint32_t *number) SA_EXPORT SA_NONNULL
SA_UNKNOWN
The state is unknown.
Definition: process.h:34
SA_RUNNING
The process is running.
Definition: process.h:35
sa_open_process
int sa_open_process() SA_EXPORT
sa_process_activity::sys_time
uint64_t sys_time
Kernel mode jiffies.
Definition: process.h:56
sa_process::gid
gid_t gid
Id of the user's group running this process.
Definition: process.h:80
sa_process::start_time
uint64_t start_time
Process start time in hundredths of second since system boot.
Definition: process.h:104
sa_process::tty
pid_t tty
The id of the tty this process is running on.
Definition: process.h:98
sa_process_activity::pid
pid_t pid
The id of the process.
Definition: process.h:47
sa_process::filename
char filename[SA_PROCESS_FILENAME]
The name of the running file.
Definition: process.h:83
sa_process::pid
pid_t pid
The id of the process.
Definition: process.h:74
sa_process_activity
Definition: process.h:45
sa_get_process_activity
int sa_get_process_activity(pid_t pid, struct sa_process_activity *dst) SA_EXPORT SA_NONNULL
sa_process_activity::rss
uint32_t rss
Resident Set memory Size.
Definition: process.h:65
SA_SLEEPING
The process is sleeping.
Definition: process.h:36
SA_SLEEPING_UNINTERRUPTIBLE
The process is an uninterruptible sleep.
Definition: process.h:37
sa_close_process
int sa_close_process() SA_EXPORT
sa_process_activity::vm_size
uint32_t vm_size
Virtual memory size.
Definition: process.h:62
sa_process
Definition: process.h:72
sa_process_activity::threads
uint32_t threads
Number of threads.
Definition: process.h:59
sa_process_activity::user_time
uint64_t user_time
User mode jiffies.
Definition: process.h:53
sa_process_activity::state
enum sa_process_state state
The current state of the process.
Definition: process.h:50
sa_process::nice
int8_t nice
Priority of this process.
Definition: process.h:101
sa_get_processes_ids
int sa_get_processes_ids(pid_t *dst, uint32_t dst_size, uint32_t *written) SA_EXPORT SA_NONNULL
sa_process::parent_pid
pid_t parent_pid
The id of its parent.
Definition: process.h:89
SA_ZOMBIE
It has completed execution but still has an entry in the process table.
Definition: process.h:38
sa_process::cmdline
char cmdline[SA_PROCESS_CMDLINE]
The command executed to launch this process.
Definition: process.h:86
sa_process::uid
uid_t uid
The id of the user running this process.
Definition: process.h:77
sa_process::sid
pid_t sid
Session id of this process.
Definition: process.h:95
SA_STOPPED
The process is traced or stopped.
Definition: process.h:39