int main(int argc, char *argv[]){ if (argc == 1) { perror("Write filename in the command line when you start the programm"); exit(1); } FILE *input = fopen(argv[1],"r"); char command[500], time_char[50]; double time_sec; pid_t pid, pid_longest; double time_longest = 0; read_s(input, command, time_char); do { sscanf(time_char, "%lf", &time_sec); if ((pid = fork()) == 0) { assert(usleep(1000*1000*time_sec) == 0); // printf("Command = %s Time = %s\n", command, time_char); execlp(command, command, (char*) NULL); exit(1); } if (time_sec > time_longest) { time_longest = time_sec; pid_longest = pid; } read_s(input, command, time_char); } while (!feof(input)); int status; waitpid(pid_longest, &status, 0); fclose(input); return 0; }
CELLP read_f(CELLP arg) { FILE* nfp = cur_fpi; CELLP cp; // ファイルディスクリプタが指定された時 if (dirin(arg) != (CELLP)nil) { ec; cp = read_s(TOP); pushbuf(); cur_fpi = nfp; return cp; } cp = read_s(TOP); return read_s(TOP); }
int main (void) { int rc; char buf[100] = { 0 }; setup(); sock = socket (AF_INET, SOCK_STREAM, 0); assert (sock >= 0); sock_name.sin_family = AF_INET; sock_name.sin_port = htons (test_port); sock_name.sin_addr.s_addr = htonl (INADDR_LOOPBACK); assert (bind(sock, (struct sockaddr*)&sock_name, sizeof(sock_name)) != -1); sock_name.sin_family = AF_INET; sock_name.sin_port = htons (test_port); sock_name.sin_addr.s_addr = htonl (INADDR_LOOPBACK); assert (connect(sock, (struct sockaddr*)&sock_name, sizeof(sock_name)) != -1); do { rc = sock_select (sock); } while (rc < 0); assert (write_s(sock,"HELO",4) != -1); assert (read_s (sock,buf,sizeof(buf)) != -1); printf ("buf = `%s'\n", buf); assert (write_s(sock,"QUIT",4) != -1); assert (close_s(sock) != -1); sock = -1; return (0); }
int main() { std::istringstream iss("happy birthday"); auto state = read_s(iss).rdstate(); return 0; }