All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH RFC 1/2] lib: add SAFE_READ_PROC_STATUS macro
@ 2021-01-25  6:47 Li Wang
  2021-01-25  6:47 ` [LTP] [PATCH RFC 2/2] swapping01: check memory swap usage per process Li Wang
  2021-01-25  8:29 ` [LTP] [PATCH RFC 1/2] lib: add SAFE_READ_PROC_STATUS macro Petr Vorel
  0 siblings, 2 replies; 7+ messages in thread
From: Li Wang @ 2021-01-25  6:47 UTC (permalink / raw)
  To: ltp

To parse /proc/PID/status files, for example:
    SAFE_READ_PROC_STATUS(pid, "VmSwap:");

Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Petr Vorel <pvorel@suse.cz>
Cc: Alexander Egorenkov <egorenar@linux.ibm.com>
---
 include/tst_safe_file_ops.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/tst_safe_file_ops.h b/include/tst_safe_file_ops.h
index 894c16123..7a4076c4c 100644
--- a/include/tst_safe_file_ops.h
+++ b/include/tst_safe_file_ops.h
@@ -25,6 +25,14 @@
                         &tst_rval); \
         tst_rval;})
 
+#define SAFE_READ_PROC_STATUS(pid, item) \
+       ({long tst_rval_; \
+        char tst_path_[128]; \
+        sprintf(tst_path_, "/proc/%d/status", pid); \
+        SAFE_FILE_LINES_SCANF(tst_path_, item " %ld", \
+                        &tst_rval_); \
+        tst_rval_;})
+
 #define FILE_PRINTF(path, fmt, ...) \
 	file_printf(__FILE__, __LINE__, \
 		    (path), (fmt), ## __VA_ARGS__)
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-24  8:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25  6:47 [LTP] [PATCH RFC 1/2] lib: add SAFE_READ_PROC_STATUS macro Li Wang
2021-01-25  6:47 ` [LTP] [PATCH RFC 2/2] swapping01: check memory swap usage per process Li Wang
2021-01-25  8:28   ` Petr Vorel
2021-01-25 15:25   ` Cyril Hrubis
2021-01-26  5:25     ` Li Wang
2021-02-24  8:04       ` Li Wang
2021-01-25  8:29 ` [LTP] [PATCH RFC 1/2] lib: add SAFE_READ_PROC_STATUS macro Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.