1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* Fluent Bit 4 * ========== 5 * Copyright (C) 2019-2021 The Fluent Bit Authors 6 * Copyright (C) 2015-2018 Treasure Data Inc. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 #ifndef IN_MEM_PROC_H 22 #define IN_MEM_PROC_H 23 24 #define PROC_PID_SIZE 1024 25 #define PROC_STAT_BUF_SIZE 1024 26 27 /* 28 * This 'stat' format omits the first two fields, due to the nature 29 * of sscanf(3) and whitespaces, programs with spaces in the name can 30 * screw up when scanning the information. 31 */ 32 #define PROC_STAT_FORMAT "%c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %llu %lu %ld" 33 34 /* Our tast struct to read the /proc/PID/stat values */ 35 struct proc_task { 36 int pid; /* %d */ 37 char comm[256]; /* %s */ 38 char state; /* %c */ 39 int ppid; /* %d */ 40 int pgrp; /* %d */ 41 int session; /* %d */ 42 int tty_nr; /* %d */ 43 int tpgid; /* %d */ 44 unsigned int flags; /* %u */ 45 unsigned long minflt; /* %lu */ 46 unsigned long cminflt; /* %lu */ 47 unsigned long majflt; /* %lu */ 48 unsigned long cmajflt; /* %lu */ 49 unsigned long utime; /* %lu */ 50 unsigned long stime; /* %lu */ 51 long cutime; /* %ld */ 52 long cstime; /* %ld */ 53 long priority; /* %ld */ 54 long nice; /* %ld */ 55 long num_threads; /* %ld */ 56 long itrealvalue; /* %ld */ 57 unsigned long long starttime; /* %llu */ 58 unsigned long vsize; /* %lu */ 59 long rss; /* %ld */ 60 61 /* Internal conversion */ 62 long proc_rss; /* bytes = (rss * PAGESIZE) */ 63 char *proc_rss_hr; /* RSS in human readable format */ 64 }; 65 66 struct proc_task *proc_stat(pid_t pid, int page_size); 67 void proc_free(struct proc_task *t); 68 69 #endif 70