4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <sys/types.h>
27 #include <sensor_common.h>
28 #include "sensor_log.h"
33 bool get_proc_name(pid_t pid, char *process_name)
37 char filename[PATH_MAX];
39 sprintf(filename, "/proc/%d/stat", pid);
40 fp = fopen(filename, "r");
45 if (fscanf(fp, "%*s (%[^)]", buf) < 1) {
50 strncpy(process_name, buf, NAME_MAX-1);
51 process_name[NAME_MAX-1] = '\0';
57 bool get_proc_name(pid_t pid, char *process_name)
61 if (snprintf(buf, sizeof(buf), "%d process", pid) < 1) {
65 strncpy(process_name, buf, NAME_MAX-1);
66 process_name[NAME_MAX-1] = '\0';
72 const char* get_client_name(void)
74 const int pid_string_size = 10;
75 static pid_t pid = -1;
76 static char client_name[NAME_MAX + pid_string_size];
78 char proc_name[NAME_MAX];
83 get_proc_name(pid, proc_name);
84 snprintf(client_name, sizeof(client_name), "%s(%d)", proc_name, pid);