diff options
author | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-07 11:23:14 +0100 |
---|---|---|
committer | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-07 11:23:14 +0100 |
commit | cedb83232379d80a9abd2ca72e60d64e5b50d92b (patch) | |
tree | 9e538cba06d5f052b24436adc870ec978e991496 /src | |
parent | d72e395ac6107e89b92e1c931b4b84ca42f60c2b (diff) | |
download | cpulimit-cedb83232379d80a9abd2ca72e60d64e5b50d92b.tar.gz |
removed process_exists(), code compiled on Linux and FreeBSD with same Makefile using gmake
Diffstat (limited to 'src')
-rwxr-xr-x | src/Makefile | 8 | ||||
-rw-r--r-- | src/process.c | 2 | ||||
-rw-r--r-- | src/procutils.c | 29 |
3 files changed, 16 insertions, 23 deletions
diff --git a/src/Makefile b/src/Makefile index 6e7a89e..bacec4b 100755 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,13 @@ CC?=gcc CFLAGS?=-Wall -O2 -D_GNU_SOURCE TARGETS=cpulimit -LIBS=process.o procutils.o list.o -lkvm +LIBS=process.o procutils.o list.o + +UNAME := $(shell uname) + +ifeq ($(UNAME), FreeBSD) +LIBS+=-lkvm +endif all:: $(TARGETS) diff --git a/src/process.c b/src/process.c index 73c5883..53226a7 100644 --- a/src/process.c +++ b/src/process.c @@ -134,6 +134,8 @@ static int get_starttime(pid_t pid) struct process proc; get_proc_info(&proc, pid); return proc.starttime; +#elif defined __FreeBSD__ + return -1; #endif } diff --git a/src/procutils.c b/src/procutils.c index 7cf0e71..19b7054 100644 --- a/src/procutils.c +++ b/src/procutils.c @@ -68,6 +68,8 @@ static pid_t getppid_of(pid_t pid) struct process p; get_proc_info(&p, pid); return p.ppid; +#elif defined __FreeBSD__ + #endif } @@ -88,20 +90,6 @@ static int is_kernel_thread(pid_t pid) } #endif -//deprecated -// returns 1 if pid is an existing pid, 0 otherwise -static int process_exists(pid_t pid) { -#ifdef __linux__ - static char procdir[20]; - struct stat procstat; - sprintf(procdir, "/proc/%d", pid); - return stat(procdir, &procstat)==0; -#elif defined __APPLE__ - struct process p; - return get_proc_info(&p, pid)==0; -#endif -} - /* PID HASH FUNCTIONS */ static int hash_process(struct process_family *f, struct process *p) @@ -203,13 +191,13 @@ int init_process_iterator(struct process_iterator *i) { /* Open the kvm interface, get a descriptor */ if ((kd = kvm_open(NULL, NULL, NULL, 0, errbuf)) == NULL) { /* fprintf(stderr, "kvm_open: %s\n", errbuf); */ - fprintf(stderr, "kvm_open: ", errbuf); + fprintf(stderr, "kvm_open: %s", errbuf); } /* Get the list of processes. */ if ((procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, &count)) == NULL) { kvm_close(kd); /* fprintf(stderr, "kvm_getprocs: %s\n", kvm_geterr(kd)); */ - fprintf(stderr, "kvm_getprocs: ", kvm_geterr(kd)); + fprintf(stderr, "kvm_getprocs: %s", kvm_geterr(kd)); } #endif @@ -409,14 +397,11 @@ void cleanup_process_family(struct process_family *f) // look for a process by pid // search_pid : pid of the wanted process -// return: pid of the found process, if it is found -// 0, if it's not found -// negative pid, if it is found but it's not possible to control it +// return: pid of the found process, if successful +// negative pid, if the process does not exist or if the signal fails int look_for_process_by_pid(pid_t pid) { - if (process_exists(pid)) - return (kill(pid,0)==0) ? pid : -pid; - return 0; + return (kill(pid,0)==0) ? pid : -pid; } // look for a process with a given name |