JM プロジェクトは、主に Linux 関連のマニュアルページの日本語ページを翻訳・公開しています。
... である。 このプログラムを実行すると、以下のような出力が得られる: $ ./a.out main: swapcontext(&uctx_main, &uctx_func2) func2: started func2: swapcontext(&uctx_func2, &uctx_func1) func1: started func1: swapcontext(&uctx_func1, &uctx_func2) func2: returning ... c2; #define handle_error(msg) \ do { perror(msg); exit(EXIT_FAILURE); } while (0) static void func1(void) { printf("func1: started\n"); printf("func1: swapcontext(&uctx_func1, &uctx_func2)\n"); if (swapcontext(&uctx_func1, &uctx_func2) == -1) handle_err ... or("swapcontext"); printf("func1: returning\n"); } static void func2(void) { printf("func2: started\n"); printf("func2: swapcontext(&uctx_func2, &uctx_func1)\n"); if (swapcontext(&uctx_func2, &uctx_func1) == -1) handle_err ... ... である。 このプログラムを実行すると、以下のような出力が得られる: $ ./a.out main: swapcontext(&uctx_main, &uctx_func2) func2: started func2: swapcontext(&uctx_func2, &uctx_func1) func1: started func1: swapcontext(&uctx_func1, &uctx_func2) func2: returning ... c2; #define handle_error(msg) \ do { perror(msg); exit(EXIT_FAILURE); } while (0) static void func1(void) { printf("func1: started\n"); printf("func1: swapcontext(&uctx_func1, &uctx_func2)\n"); if (swapcontext(&uctx_func1, &uctx_func2) == -1) handle_err ... or("swapcontext"); printf("func1: returning\n"); } static void func2(void) { printf("func2: started\n"); printf("func2: swapcontext(&uctx_func2, &uctx_func1)\n"); if (swapcontext(&uctx_func2, &uctx_func1) == -1) handle_err ... ... たりする。 以下のシェルセッションでは、メインスレッドはもう一つのスレッドに キャンセル要求を送信する。 $ ./a.out New thread started cnt = 0 cnt = 1 Canceling thread Called clean-up handler Thread was canceled; cnt = 0 上記の実行例から、スレッドがキャンセ ... 例では、メインプログラムはグローバル変数を設定して、 もう一つのスレッドが正常終了するようにしている。 $ ./a.out x New thread started cnt = 0 cnt = 1 Thread terminated normally; cnt = 2 上記では、 ( cleanup_pop_arg が 0 なので) クリーンアップハンドラーは 実 ... して、 もう一つのスレッドが正常終了するようにし、さらに cleanup_pop_arg に 0 以外の値を渡している。 $ ./a.out x 1 New thread started cnt = 0 cnt = 1 Called clean-up handler Thread terminated normally; cnt = 0 上記では、スレッドはキャンセルされていないが、 ... ... たりする。 以下のシェルセッションでは、メインスレッドはもう一つのスレッドに キャンセル要求を送信する。 $ ./a.out New thread started cnt = 0 cnt = 1 Canceling thread Called clean-up handler Thread was canceled; cnt = 0 上記の実行例から、スレッドがキャンセ ... 例では、メインプログラムはグローバル変数を設定して、 もう一つのスレッドが正常終了するようにしている。 $ ./a.out x New thread started cnt = 0 cnt = 1 Thread terminated normally; cnt = 2 上記では、 ( cleanup_pop_arg が 0 なので) クリーンアップハンドラーは 実 ... して、 もう一つのスレッドが正常終了するようにし、さらに cleanup_pop_arg に 0 以外の値を渡している。 $ ./a.out x 1 New thread started cnt = 0 cnt = 1 Called clean-up handler Thread terminated normally; cnt = 0 上記では、スレッドはキャンセルされていないが、 ... ... _CANCELED かどうかを 確認する。以下のシェルセッションはこのプログラムを実行した際の実行例である。 $ ./a.out thread_func(): started; cancellation disabled main(): sending cancellation request thread_func(): about to enable cancellation main(): thread was ... ancelstate(PTHREAD_CANCEL_DISABLE, NULL); if (s != 0) handle_error_en(s, "pthread_setcancelstate"); printf("thread_func(): started; cancellation disabled\n"); sleep (5); printf("thread_func(): about to enable cancellation\n"); s = pthread_setcancelstate ... hr, NULL, &thread_func, NULL); if (s != 0) handle_error_en(s, "pthread_create"); sleep (2); /* Give thread a chance to get started */ printf("main(): sending cancellation request\n"); s = pthread_cancel(thr); if (s != 0) handle_error_en(s, "pthread_canc ... ... トし、 init を起動する: ifconfig lo 127.0.0.1 up # for portmap # configure Ethernet or such portmap # for lockd (implicitly started by mount) mount -o ro 10.0.0.1:/my_root /mnt killall portmap # portmap keeps old root busy cd /mnt pivot_root . old_root e ... ... 三引き数は省略可能である。 以下のシェルのセッションはこのプログラムの使用例を示したものである。 $ a.out 3 1 100 0.000: timer started 3.000: read: 1; total=1 4.000: read: 1; total=2 ^Z # type control-Z to suspend the program [1]+ Stopped ./timerfd3_demo 3 ... ttime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == -1) handle_error("timerfd_settime"); print_elapsed_time(); printf("timer started\n"); for (tot_exp = 0; tot_exp < max_exp;) { s = read(fd, &exp, sizeof(uint64_t)); if (s != sizeof(uint64_t)) handle_error ... ... 三引き数は省略可能である。 以下のシェルのセッションはこのプログラムの使用例を示したものである。 $ a.out 3 1 100 0.000: timer started 3.000: read: 1; total=1 4.000: read: 1; total=2 ^Z # type control-Z to suspend the program [1]+ Stopped ./timerfd3_demo 3 ... ttime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == -1) handle_error("timerfd_settime"); print_elapsed_time(); printf("timer started\n"); for (tot_exp = 0; tot_exp < max_exp;) { s = read(fd, &exp, sizeof(uint64_t)); if (s != sizeof(uint64_t)) handle_error ... ... 三引き数は省略可能である。 以下のシェルのセッションはこのプログラムの使用例を示したものである。 $ a.out 3 1 100 0.000: timer started 3.000: read: 1; total=1 4.000: read: 1; total=2 ^Z # type control-Z to suspend the program [1]+ Stopped ./timerfd3_demo 3 ... ttime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == -1) handle_error("timerfd_settime"); print_elapsed_time(); printf("timer started\n"); for (tot_exp = 0; tot_exp < max_exp;) { s = read(fd, &exp, sizeof(uint64_t)); if (s != sizeof(uint64_t)) handle_error ... ... 情報を表示して終了する。 -h , --help ヘルプを表示して終了する。 用例 % script --log-timing file.tm --log-in script.in Script started, file is script.out % date <etc, etc> % exit Script done, file is script.out % scriptlive --log-timing file.tm --log-in sc ... 日本語の文書やマニュアルを配布している個人/プロジェクトへのリンクです。