int main(int argc, char * argv[]) { // fork and execute the dataserver from (current) parent pid_t PID; if( (PID = fork()) < 0 ) { // error catching fprintf(stderr, "fork() error\n"); return 1; // ERROR: should not happen } else if ( PID == 0 ) { // Child code block // execvp() if ( execvp("./dataserver", argv) < 0 ) { fprintf(stderr, "execvp() error\n"); return 1; } printf("Should not print.\n"); } // Parent continues with requests usleep(100000); RequestChannel chanel("control",RequestChannel::CLIENT_SIDE); // construct client side pipe usleep(1000000); // test with "hello" string reply1 = chanel.send_request("hello"); std::cout << "Reply to request 'hello' is '" << reply1 << "'" << std::endl << flush; printf("=============TIMING=REQUEST========================\n"); assert(gettimeofday(&tp_start, 0) == 0); // test with "hello" reply1 = chanel.send_request("data " + int2string(4) ); std::cout << "Reply to request 'data 4' is '" << reply1 << "'" << std::endl << flush; assert(gettimeofday(&tp_end, 0) == 0); printf("Time taken for server request: "); print_time_diff(&tp_start, &tp_end); printf("\n"); printf("=============TIMING=REQUEST========================\n"); printf("=============TIMING=FAKE=REQUEST========================\n"); assert(gettimeofday(&tp_start, 0) == 0); // test with fake request reply1 = fake_request("This is a fake request."); std::cout << "Reply to request 'This is a fake request.' is '" << reply1 << "'" << std::endl << flush; assert(gettimeofday(&tp_end, 0) == 0); printf("Time taken for fake request: "); print_time_diff(&tp_start, &tp_end); printf("\n"); printf("=============TIMINGFAKE==REQUEST========================\n"); // test close with "quit" reply1 = chanel.send_request("quit"); std::cout << "Reply to request 'quit' is '" << reply1 << "'" << std::endl << flush; wait(&PID); return 0; }
// A util function to print all the results stored in lists void print_results() { printf("\n\n=============== Summary ===============\n\n"); print_date(&start_ts); print_time_diff(&start_ts, &end_ts); printf(" Packet Count\t: %d\n", pkt_cnt); printf(" Smallest\t: %d bytes\n", smallest); printf(" Largest\t: %d bytes\n", largest); printf(" Average\t: %.2f bytes\n", tot_size / pkt_cnt); printf("\n============= Link Layer =============\n"); printf("\n--- Source Ethernet Addresses ---\n\n"); print_map(&src_eth_info, 0); printf("\n--- Destination Ethernet Addresses ---\n\n"); print_map(&dst_eth_info, 0); printf("\n============= Network Layer =============\n"); printf("\n--- Network Layer Protocols ---\n\n"); print_map(&nw_prot_info, 0); printf("\n--- Source IP Addresses ---\n\n"); print_map(&src_ip_info, 0); printf("\n--- Destination IP Addresses ---\n\n"); print_map(&dst_ip_info, 0); printf("\n---------- TTLs ----------\n\n"); print_int_map(&ttl_info, 0); printf("\n--- Unique ARP Participants ---\n\n"); print_map(&arp_info, 1); printf("\n============= Transport Layer =============\n"); printf("\n--- Transport Layer Protocols ---\n\n"); print_map(&trns_prot_info, 0); printf("\n========== Transport Layer : TCP ==========\n"); printf("\n--- Source TCP Ports ---\n\n"); print_int_map(&src_tcp_ports_info, 0); printf("\n--- Destination TCP Ports ---\n\n"); print_int_map(&dst_tcp_ports_info, 0); printf("\n---------- TCP Flags ----------\n\n"); print_map(&tcp_flag_info, 0); printf("\n---------- TCP Options ----------\n\n"); print_map(&tcp_opt_info, 0); printf("\n========== Transport Layer : UDP ==========\n"); printf("\n--- Source UDP Ports ---\n\n"); print_int_map(&src_udp_ports_info, 0); printf("\n--- Destination UDP Ports ---\n\n"); print_int_map(&dst_udp_ports_info, 0); printf("\n========== Transport Layer : ICMP ==========\n"); printf("\n--- Source IPs for ICMP ---\n\n"); print_map(&icmp_src_ip_info, 0); printf("\n--- Destination IPs for ICMP ---\n\n"); print_map(&icmp_dst_ip_info, 0); printf("\n--- ICMP Types ---\n\n"); print_int_map(&icmp_type_info, 0); printf("\n--- ICMP Codes ---\n\n"); print_int_map(&icmp_code_info, 0); printf("\n--- ICMP Responses ---\n\n"); print_map(&icmp_cat_info, 0); printf("\n\n"); }
extern void ackerman_main() { /* This is function repeatedly asks the user for the two parameters "n" and "m" to pass to the ackerman function, and invokes the function. Before and after the invocation of the ackerman function, the value of the wallclock is taken, and the elapsed time for the computation of the ackerman function is output. */ int n, m; /* Parameter for the invocation of the Ackerman function. */ struct timeval tp_start; /* Used to compute elapsed time. */ struct timeval tp_end; for (;;) { num_allocations = 0; printf("\n"); printf("Please enter parameters n and m to ackerman function.\n"); printf("Note that this function takes a long time to compute,\n"); printf("even for small values. Keep n at or below 3, and m at or\n"); printf("below 8. Otherwise, the function takes seemingly forever.\n"); printf("Enter 0 for either n or m in order to exit.\n\n"); printf(" n = "); scanf("%d", &n); if (!n) break; printf(" m = "); scanf("%d", &m); if (!m) break; printf(" n = %d, m = %d\n", n, m); assert(gettimeofday(&tp_start, 0) == 0); /* Assert aborts if there is a problem with gettimeofday. We rather die of a horrible death rather than returning invalid timing information! */ int result = ackerman(n, m); assert(gettimeofday(&tp_end, 0) == 0); /* (see above) */ printf("Result of ackerman(%d, %d): %d\n", n, m, result); printf("Time taken for computation : "); print_time_diff(&tp_start, &tp_end); printf("\n"); printf("Number of allocate/free cycles: %lu\n\n\n", num_allocations); } printf("Reached end of Ackerman program. Thank you for using it.\n"); }
/** * Extension of print_time_diff to add on the .s for timer mode * @param d device to print to * @param cur current time * @param last the last time to be printed on the screen */ void print_time_diff_ex(device_t d, unsigned int cur, unsigned int last) { if (last/1000 != cur/1000) { dputs(d, ""); print_time_diff(d, cur, last); dputchar(d, '.'); dputchar(d, '0' + (cur/100)%10); } else if ((last/100)%10 != (cur/100)%10) { dputchar(d, ''); dputchar(d, '0' + (cur/100)%10); } }
int main(int argc, char **argv) { cpu_set_t mask; timespec start, end; list = NULL; CPU_ZERO(&mask); CPU_SET(0, &mask); sched_setaffinity(0, sizeof(mask), &mask); pgsz = sysconf(_SC_PAGESIZE); counter = 0; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); allocate(); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); print_time_diff(start, end); return 0; }