blob: c3ed21a0ee47359a49e34bd0125fbaf24b10ff67 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h> /* for strerror() */
#include <errno.h>
#include "busybox.h"
extern int optind; /* in unistd.h */
extern int errno; /* for use with strerror() */
static char *opt_pattern = NULL;
extern int pgrep_main(int argc, char **argv)
{
int opt;
pid_t* pidList;
/* do normal option parsing */
while ((opt = getopt(argc, argv, "f")) > 0) {
switch (opt) {
case 'f':
break;
default:
show_usage();
}
}
if (argc - optind == 1)
opt_pattern = argv[optind];
if (!opt_pattern)
show_usage();
pidList = find_pid_by_name(opt_pattern);
if (!pidList || *pidList<=0) {
return EXIT_SUCCESS;
}
for(; pidList && *pidList!=0; pidList++) {
printf("%d\n", *pidList);
}
return EXIT_SUCCESS;
}
|