作业社区
探索学习新天地,共享知识资源!
阿大月 的学生作业:
#include using namespace std; class times{ private: int hours; int minute; int second; public: void set_hours(int _hour); void set_minute(int _minute); void set_second(int _second); void print_time(); }; void times::set_hours(int _hour){ hours = _hour; } void times::set_minute(int _minute){ minute = _minute; } void times::set_second(int _second){ second = _second; } void times::print_time(){ cout
+12
浪潮君 的学生作业:
#include int main() { // 定义二维数组,2行3列 int a[2][3] = {10, 20, 30, 40, 50, 60}; // ------------------------------- // 使用数组指针(int (*)[3])来输出 // ------------------------------- int (*p)[3] = a; // 定义一个数组指针p,指向一维数组(3个int) printf("使用数组指针输出二维数组内容:\n"); for (int i = 0; i < 2; i++) { // 遍历行 for (int j = 0; j < 3; j++) { // 遍历列 printf("%d ", p[i][j]); // 通过p[i][j]访问元素 } } printf("\n"); // ------------------------------- // 使用指针数组(int *p_arr[2])来输出 // ------------------------------- int *p_arr[2]; // 定义一个指针数组,数组里每个元素是int * // 初始化指针数组,让每个指针分别指向a的一行 for (int i = 0; i < 2; i++) { p_arr[i] = a[i]; } printf("使用指针数组输出二维数组内容:\n"); for (int i = 0; i < 2; i++) { // 遍历行 for (int j = 0; j < 3; j++) { // 遍历列 printf("%d ", p_arr[i][j]); // 通过p_arr[i][j]访问元素 } } printf("\n"); return 0; }
+21
慕运维8597106 的学生作业:
#include #include #include #include #include #include #include void do_user2_sig(int sig) { printf("Received : %s\n", strsignal(sig)); } int main(int argc, char const *argv[]) { pid_t cpid1, cpid2; cpid1 = fork(); if (signal(SIGUSR2, do_user2_sig) == SIG_ERR) { perror("[ERROR] signal():"); exit(EXIT_FAILURE); } if (cpid1 == -1) { perror("[ERROR] fork:"); exit(EXIT_FAILURE); } else if (cpid1 == 0) { pause(); printf("Child Process A Resume!\n"); exit(EXIT_SUCCESS); } else if (cpid1 > 0) { cpid2 = fork(); if (cpid2 == -1) { perror("[ERROR] fork:"); exit(EXIT_FAILURE); } else if (cpid2 == 0) { pause(); printf("Child Process B Resume!\n"); exit(EXIT_SUCCESS); } else if (cpid2 > 0) { sleep(3); kill(cpid1,SIGUSR1); kill(cpid2,SIGUSR2); waitpid(cpid1,NULL,0); waitpid(cpid2,NULL,0); } } return 0; } **运行结果:**只有Bpause后面的代码执行了,因为SIGUSR2被自定义了,而A进程收到SIGUSR1是终止进程,所以后面代码不执行 linux@linux:~/learn/chapter12$ ./a.out Received : User defined signal 2 Child Process B Resume!
+92
慕运维8597106 的学生作业:
#include #include #include #include #include #include int main(void) { pid_t cpid1,cpid2; cpid1 = fork(); if(cpid1 == -1) { perror("[ERROR] fork"); exit(EXIT_FAILURE); } else if(cpid1 == 0) { raise(SIGSTOP); } else if(cpid1 > 0) {// 主进程 cpid2 = fork(); if(cpid2 == -1) { perror("[ERROR] fork"); exit(EXIT_FAILURE); }else if(cpid2 == 0) { pause(); } else if(cpid2 > 0) {// 主进程 sleep(3); kill(cpid1,SIGKILL); printf("Father killed Child: %d\n",cpid1); kill(cpid2,SIGKILL); printf("Father killed Child: %d\n",cpid2); waitpid(cpid1,NULL,0); waitpid(cpid2,NULL,0); } } return 0; }
+98