• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

oga's tools


Commit MetaInfo

Revisione9ffd7fe1f9e7b52310aeacf1fd585175d971795 (tree)
Time2024-05-01 00:14:05
Authorhyperoga <hyperoga@gmai...>
Commiterhyperoga

Log Message

V1.03 support ext meminfo file

Change Summary

Incremental Difference

--- a/cmem.c
+++ b/cmem.c
@@ -4,6 +4,7 @@
44 * 2001/12/09 V1.00 based xmem V0.33 by oga.
55 * 2005/09/11 V1.01 support Linux 2.6.x
66 * 2022/05/22 V1.02 add description to usage
7+ * 2024/02/05 V1.03 support ext meminfo file
78 */
89
910 #include <stdio.h>
@@ -13,7 +14,7 @@
1314 #include <unistd.h>
1415 #include <errno.h>
1516
16-#define VER "Ver 1.02"
17+#define VER "Ver 1.03"
1718 #define S_MEM "Memory"
1819 #define S_SWAP "Swap"
1920
@@ -23,7 +24,8 @@
2324 #define dprintf if (vf) printf
2425
2526 /* globals */
26-int vf = 0; /* verbose flag */
27+int vf = 0; /* verbose flag */
28+char *meminfo = "/proc/meminfo"; /* meminfo file V1.03-A */
2729
2830 #ifdef COMMENT
2931 (MB)0 10 20 30 40 50 60 70
@@ -163,8 +165,9 @@ void get_memdata(mem_t *mem)
163165 char buf[1024];
164166 char *pt;
165167
166- if (!(fp = fopen("/proc/meminfo","r"))) {
167- perror("fopen /proc/meminfo");
168+ if (!(fp = fopen(meminfo, "r"))) { /* V1.03-C */
169+ sprintf(buf, "fopen %s", meminfo); /* V1.03-C */
170+ perror(buf); /* V1.03-C */
168171 exit(1);
169172 }
170173 fgets(buf,sizeof(buf),fp); /* skip header */
@@ -458,13 +461,18 @@ int main(int a, char *b[])
458461
459462 for (i = 1; i<a ; i++) {
460463 if (!strncmp(b[i],"-h",2)) {
461- printf("usage : cmem [-update <time>]\n");
464+ printf("usage : cmem [-update <time>] [-memfile <meminfo_file>]\n");
462465 printf(" # : used\n");
463466 printf(" * : cached\n");
464467 printf(" = : buffers\n");
465468 printf(" . : free\n");
466469 exit(1);
467470 }
471+ /* V1.03-A start */
472+ if (!strncmp(b[i],"-m",2) && a > i) {
473+ meminfo = b[++i]; /* meminfo file*/
474+ }
475+ /* V1.03-A end */
468476 if (!strncmp(b[i],"-u",2) && a > i) {
469477 wait = atoi(b[++i]); /* update time */
470478 }
@@ -539,9 +547,9 @@ int main(int a, char *b[])
539547 for (i = 1; i<8; i++) {
540548 if (UNIT >= 20 && i == 7) {
541549 /* max 79char */
542- printf(" %-3d", i*UNIT);
550+ printf(" %-4d", i*UNIT);
543551 } else {
544- printf(" %-3d", i*UNIT);
552+ printf(" %-4d", i*UNIT);
545553 }
546554 }
547555 printf("\n");