test.c
/*
* Build:
* gcc -g -o test test.c
*
* Usage:
* ./test [-c max number of child] 'keyword' 'log file'
*
*/
#include <stdio.h>
#include <string.h>
#include <getopt.h>
int main(int argc, char **argv)
{
int i;
int ch;
const char *args = "c:h";
while ((ch = getopt(argc, argv, args)) != -1) {
switch (ch) {
case 'c':
max_num_child = atoi(optarg);
break;
case 'h':
default:
usage(argv[0]);
exit(0);
}
}
if ( (argc - optind) != 2) {
usage(argv[0]);
exit(0);
}
snprintf(keyword, sizeof(keyword), "%s", argv[optind++]);
snprintf(log_file, sizeof(log_file), "%s", argv[optind++]);
printf("#####################################\n");
printf("#### max number of child: %d\n", max_num_child);
printf("#### keyword: %s\n", keyword);
printf("#### log file: %s\n", log_file);
}
网友评论