📄 process.c
字号:
#include <sys/types.h>#include <signal.h>#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <time.h>int COLOR[] = { 31, 32, 33, 34, 35, 36 };const int COLOR_NUM = sizeof( COLOR ) / sizeof( COLOR[0] );pid_t pid;unsigned int t;int color;void term_handler( int sig ){ printf( "\033[;;%dmPid %d terminated, time runned: %u sec.\033[m\n", color, pid, t ); signal( sig, SIG_DFL ); raise( sig );}//end term_handlervoid susp_handler( int sig ){ printf( "\033[;;%dmPid %d suspended.\033[m\n", color, pid ); signal( sig, SIG_DFL ); raise( sig );}//end susp_handlervoid resu_handler( int sig ){ signal( SIGTSTP, susp_handler ); printf( "\033[;;%dmPid %d resumed.\033[m\n", color, pid );}//end resu_handlerint main(void){ struct timespec ts, tr; nice( 10 ); pid = getpid(); srand( time(NULL) * pid ); color = COLOR[ rand() % COLOR_NUM ]; signal( SIGINT, term_handler ); signal( SIGTSTP, susp_handler ); signal( SIGCONT, resu_handler ); printf( "\033[;;%dmPid %d starts.\033[m\n", color, pid ); ts.tv_sec = 0; ts.tv_nsec = 500000000; for( t = 0; t < 19; ) { nanosleep( &ts, &tr ); ++t; printf( "\033[;;%dmTime running: %d\033[m\n", color, t ); nanosleep( &ts, &tr ); }//end for sleep( 1 ); ++t; printf( "\033[;;%dmPid %d exited, time runned: %u sec.\033[m\n", color, pid, t ); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -