#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <getopt.h>
#include "parse.h"
#include "analyze.h"
+void read_args(int argc, char *argv[], struct parse_opts *opts)
+{
+ int optind = 0, c;
+ static struct option long_options[] = {
+ { .val = 'p', .name = "pid", .has_arg = 1, },
+ };
+ char short_options[] = "p:";
+
+ while (1) {
+ c = getopt_long(argc, argv, short_options, long_options,
+ &optind);
+
+ if (c == -1)
+ break;
+
+ printf("%c: %s\n", c, optarg);
+ switch (c) {
+ case 'p':
+ opts->pid = atoi(optarg);
+ opts->parse_mask = PARSE_PID;
+ break;
+ }
+ }
+}
+
int main(int argc, char *argv[])
{
struct pageframe pf;
struct process *process_list = NULL;
struct parse_opts opts;
- int pid;
- if (argc < 2) {
+ if (argc < 3) {
printf("A pid needs to be given as an argument\n");
return 1;
}
- pid = atoi(argv[1]);
+ read_args(argc, argv, &opts);
memset(&pf, 0, sizeof(pf));
- opts.parse_mask = PARSE_PID;
- opts.pid = pid;
scan_all_pids(&pf, &process_list, &opts);
print_pid_stats(&pf, process_list);