
作业社区
探索学习新天地,共享知识资源!
Linkus 的学生作业:
String(const char *str);hello w x l l o String::~String(void) #include #include "string.h" using namespace std; class String{ public: String(const char *str = NULL); String(const String &other); ~String(void); size_t size(void); void show(void); String operator+(const String &ot); friend String operator+(const String &str1, const String &str2); String &operator++(); String operator++(int); char &operator[](int idx); private: char *str; }; String::String(const char *str) { coutstr = NULL; } } String::String(const String &other) { cout str,other.str); } else { this->str = NULL; } } String String::operator+(const String &ot) { cout 0) { newStr.str = new char[len]; strcpy(newStr.str,this->str); strcat(newStr.str,ot.str); } return newStr; } void String::show(void) { cout





沫颖 的学生作业:
代码 #include #include #include #include #include #include #include #include #include int main(void) { // 进程id pid_t cpid; // 创建主进程、第一个子进程 cpid = fork(); // fork失败 if (cpid < 0) { perror("[ERROR] fork() 1:"); exit(EXIT_FAILURE); } else if (cpid == 0) { // 子进程A printf("Child Process A running,pid: %d\n", getpid()); } else if (cpid > 0) { // 让子进程A先运行 sleep(2); // 主进程 printf("Main Process running,pid: %d\n", getpid()); // 给子进程A发送SIGKILL信号 int retA; retA = kill(cpid, SIGKILL); // 成功发送 if (retA == 0) { printf("Main Process %d Killed Child Process A %d\n", getpid(), cpid); } // 等待子进程A退出 waitpid(cpid, NULL, 0); // 创建子进程B pid_t ccpid; ccpid = fork(); // fork失败 if (ccpid < 0) { perror("[ERROR] fork() 2:"); exit(EXIT_FAILURE); } else if (ccpid == 0) { // 子进程B printf("Child Process B running,pid: %d\n", getpid()); } else if (ccpid > 0) { // 先让子进程B运行 sleep(2); // 给子进程B发送SIGKILL信号 int retB; retB = kill(ccpid, SIGKILL); // 成功发送 if (retB == 0) { printf("Main Process %d Killed Child Process B %d\n", getpid(), ccpid); } // 等待子进程B退出 waitpid(ccpid, NULL, 0); } wait(NULL); // 退出 exit(EXIT_SUCCESS); } return 0; } 运行结果 linux@linux:~/Desktop/Study/CProjects/imooc-embedded/Stage05/Week12/Class04$ gcc demo_4_8.c linux@linux:~/Desktop/Study/CProjects/imooc-embedded/Stage05/Week12/Class04$ ./a.out Child Process A running,pid: 6531 Main Process running,pid: 6530 Main Process 6530 Killed Child Process A 6531 Child Process B running,pid: 6543 Main Process 6530 Killed Child Process B 6543 linux@linux:~/Desktop/Study/CProjects/imooc-embedded/Stage05/Week12/Class04$




