| | |
| | | extern char **environ; |
| | | using namespace std; |
| | | |
| | | SQueue<struct Item> *queue; |
| | | // 销毁共享内存和信号 |
| | | |
| | | void sigint_handler(int sig) { |
| | | destroy(); |
| | | // mm_destroy(); |
| | | exit(0); |
| | | } |
| | | |
| | |
| | | signal(SIGINT, sigint_handler); |
| | | remove("p.txt"); |
| | | remove("c.txt"); |
| | | int status, i = 0, processors = 5, scale = 100000; |
| | | int status, i = 0, processors = 4, scale = 100000; |
| | | pid_t productors[processors], consumers[processors]; |
| | | pid_t pid; |
| | | |
| | |
| | | int start = i * scale, end = i * scale + scale; |
| | | char cmd[1000]; |
| | | // char *argv[] = {"productor", start, end, NULL }; |
| | | const char *cmdfmt = "./productor %d %d >> p.txt"; |
| | | // const char *cmdfmt = "./single_productor %d %d >> p.txt"; |
| | | const char *cmdfmt = "./single_productor %d %d >> p.txt"; |
| | | sprintf(cmd, cmdfmt, start, end); |
| | | if (execl("/bin/bash", "bash", "-c", cmd, 0) < 0) |
| | | { |
| | |
| | | |
| | | // char cmd[1000]; |
| | | // char *argv[] = {"productor", start, end, NULL }; |
| | | const char *cmd = "./consumer >> c.txt"; |
| | | // const char *cmd = "./single_consumer >> c.txt"; |
| | | const char *cmd = "./single_consumer >> c.txt"; |
| | | if (execl("/bin/bash", "bash", "-c", cmd, 0) < 0) |
| | | { |
| | | err_exit(errno, "consumers execve"); |
| | |
| | | perror("waitpid error"); |
| | | |
| | | |
| | | destroy(); |
| | | //mm_destroy(); |
| | | |
| | | |
| | | |