static struct stat *get_pidstat(const pid_t pid, const char *filename);
static uid_t getpiduid(const pid_t pid);
static void print_matches(struct names *names_head, const opt_type opts);
+static void kill_matched_proc(struct procs *pptr, const opt_type opts);
static dev_t get_netdev(void);
int parse_mount(struct names *this_name, struct device_list **dev_list);
break;
}
} /* for */
+ } else {
+ usage(_("No process specification given"));
}
/* Check conflicting operations */
if (opts & OPT_MOUNTPOINT) {
}
if (nptr->matched_procs == NULL || !(opts & OPT_VERBOSE))
putc('\n', stderr);
+ if (opts & OPT_KILL)
+ kill_matched_proc(nptr->matched_procs, opts);
- }
+ } /* next name */
}
(unsigned long)dptr->device);
}
}
+
+/* 0 = no, 1=yes */
+static int ask(const pid_t pid)
+{
+ int c, res;
+ size_t len = 0;
+ char *line = NULL;
+
+ fflush(stdout);
+ while(1) {
+ fprintf(stderr, _("Kill process %d ? (y/N) "), pid);
+ fflush(stderr);
+ if (getline(&line, &len, stdin) < 0)
+ return 0;
+ if (line[0] == '\n') {
+ free(line);
+ return 0;
+ }
+ res = rpmatch(line);
+ if (res >= 0) {
+ free(line);
+ return res;
+ }
+ } /* while */
+}
+
+static void kill_matched_proc(struct procs *proc_head, const opt_type opts)
+{
+ struct procs *pptr;
+
+ for (pptr = proc_head ; pptr != NULL ; pptr = pptr->next ) {
+ if ( (opts & OPT_INTERACTIVE) && (ask(pptr->pid) == 0))
+ continue;
+ fprintf(stderr, "debug killing proc %d\n", pptr->pid);
+ }
+}