JM プロジェクトは、主に Linux 関連のマニュアルページの日本語ページを翻訳・公開しています。
... e < errno.h > #define handle_error_en(en, msg) \ do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) static void usage(char *prog_name, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [options]\n", prog_name); fp ... use_null_attrib = 1; break; case 'i': inheritsched_str = optarg; break; case 'm': main_sched_str = optarg; break; default: usage(argv[0], "Unrecognized option\n"); } } if (use_null_attrib && (inheritsched_str != NULL || attr_sched_str != NULL)) usage( ... s of main thread, and display the attributes */ if (main_sched_str != NULL) { if (!get_policy(main_sched_str[0], &policy)) usage(argv[0], "Bad policy for main thread (-m)\n"); param.sched_priority = strtol(&main_sched_str[1], NULL, 0); s = pthread_set ... ... e < errno.h > #define handle_error_en(en, msg) \ do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) static void usage(char *prog_name, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [options]\n", prog_name); fp ... use_null_attrib = 1; break; case 'i': inheritsched_str = optarg; break; case 'm': main_sched_str = optarg; break; default: usage(argv[0], "Unrecognized option\n"); } } if (use_null_attrib && (inheritsched_str != NULL || attr_sched_str != NULL)) usage( ... s of main thread, and display the attributes */ if (main_sched_str != NULL) { if (!get_policy(main_sched_str[0], &policy)) usage(argv[0], "Bad policy for main thread (-m)\n"); param.sched_priority = strtol(&main_sched_str[1], NULL, 0); s = pthread_set ... ... hread:\n"); display_thread_attributes(pthread_self(), "\t"); exit(EXIT_SUCCESS); /* Terminate all threads */ } static void usage(char *pname, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [-s stack-size [-a]]" " [-g guar ... ; case 'g': guard_size = strtoul(optarg, NULL, 0); break; case 's': stack_size = strtoul(optarg, NULL, 0); break; default: usage(argv[0], NULL); } } if (allocate_stack && stack_size == -1) usage(argv[0], "Specifying -a without -s makes no sense\n"); i ... f (argc > optind) usage(argv[0], "Extraneous command-line arguments\n"); if (stack_size >= 0 || guard_size > 0) { ret_attrp = attrp; s = pthread_a ... ... Command-line options can be used to specify the IPC_CREAT ( -c ) and IPC_EXCL ( -x ) flags for the call to semget (). The usage of this program is demonstrated below. We first create two files that will be used to generate keys using ftok (3), create ... include < sys/sem.h > #include < sys/stat.h > #include < stdio.h > #include < stdlib.h > #include < unistd.h > static void usage(const char *pname) { fprintf(stderr, "Usage: %s [-cx] pathname proj-id num-sems\n", pname); fprintf(stderr, " -c Use IPC_C ... gc, argv, "cx")) != -1) { switch (opt) { case 'c': flags |= IPC_CREAT; break; case 'x': flags |= IPC_EXCL; break; default: usage(argv[0]); } } if (argc != optind + 3) usage(argv[0]); key = ftok(argv[optind], argv[optind + 1][0]); if (key == -1) { perr ... ... e < sys/types.h > #include < sys/ipc.h > #include < sys/msg.h > struct msgbuf { long mtype; char mtext[80]; }; static void usage(char *prog_name, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [options]\n", prog_name); fp ... { switch (opt) { case 's': mode = 1; break; case 'r': mode = 2; break; case 't': msgtype = atoi(optarg); if (msgtype <= 0) usage(argv[0], "-t option must be greater than 0\n"); break; case 'k': msgkey = atoi(optarg); break; default: usage(argv[0], "Un ... recognized option\n"); } } if (mode == 0) usage(argv[0], "must use either -s or -r option\n"); qid = msgget(msgkey, IPC_CREAT | 0666); if (qid == -1) { perror("msgget"); ... ... e < sys/types.h > #include < sys/ipc.h > #include < sys/msg.h > struct msgbuf { long mtype; char mtext[80]; }; static void usage(char *prog_name, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [options]\n", prog_name); fp ... { switch (opt) { case 's': mode = 1; break; case 'r': mode = 2; break; case 't': msgtype = atoi(optarg); if (msgtype <= 0) usage(argv[0], "-t option must be greater than 0\n"); break; case 'k': msgkey = atoi(optarg); break; default: usage(argv[0], "Un ... recognized option\n"); } } if (mode == 0) usage(argv[0], "must use either -s or -r option\n"); qid = msgget(msgkey, IPC_CREAT | 0666); if (qid == -1) { perror("msgget"); ... ... e < sys/types.h > #include < sys/ipc.h > #include < sys/msg.h > struct msgbuf { long mtype; char mtext[80]; }; static void usage(char *prog_name, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [options]\n", prog_name); fp ... { switch (opt) { case 's': mode = 1; break; case 'r': mode = 2; break; case 't': msgtype = atoi(optarg); if (msgtype <= 0) usage(argv[0], "-t option must be greater than 0\n"); break; case 'k': msgkey = atoi(optarg); break; default: usage(argv[0], "Un ... recognized option\n"); } } if (mode == 0) usage(argv[0], "must use either -s or -r option\n"); qid = msgget(msgkey, IPC_CREAT | 0666); if (qid == -1) { perror("msgget"); ... ... モリー使用量のプロファイルを行う bash スクリプトである。 呼び出し元の環境に ( LD_PRELOAD 環境変数を使って) libmemusage.so ライブラリをプレロードする。 ld.so (8) を参照。 libmemusage.so ライブラリは、 malloc (3), calloc (3), free (3), realloc ... び出しを横取りし、 メモリー割り当て状況の追跡を行う。 追加で、 mmap (2), mremap (2), munmap (2) を追跡することもできる。 memusage は収集したデータをテキスト形式で出力することもできるし、 memusagestat (1) を使って収集したデータをグラフにした PNG ファイル ... を作成することもできる (以下の -p オプションを参照)。 メモリー使用量概要 memusage が出力する "Memory usage summary" (メモリー使用量概要) の行には以下のフィールドが含まれる。 heap total malloc (3) のすべて ... ... etrusage () は who の資源 (resource) の使用量を返す。 who には以下のいずれか一つを指定できる。 RUSAGE_SELF 呼び出したプロセスの資源 ... 使用量、 そのプロセス内の全スレッドが使用している資源の合計を返す。 RUSAGE_CHILDREN 呼び出したプロセスの子プロセスのうち、 終了して待ち状態にある全プロセスが使用している資源使用量の統計を返す。 これ ... らの統計情報には、孫プロセスやその子孫のプロセスのうち、 削除待ちのものが使用している資源も含まれる。 RUSAGE_THREAD (Linux 2.6.26 以降) 呼び出したスレッドに関する資源使用量の統計を返す。 < sys/resource.h > からこの定数の定義を得るた ... ... and terminate the calling process */ #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) static void usage(char *pname) { fprintf(stderr, "Usage: %s [options] program [arg...]\n", pname); fprintf(stderr, "Options can be:\n"); fpr ... : flags |= CLONE_NEWTIME; break; case 'u': flags |= CLONE_NEWUTS; break; case 'U': flags |= CLONE_NEWUSER; break; default: usage(argv[0]); } } if (optind >= argc) usage(argv[0]); if (unshare(flags) == -1) errExit("unshare"); execvp(argv[optind], &argv ... 日本語の文書やマニュアルを配布している個人/プロジェクトへのリンクです。