--- /dev/null
+/* MIT License
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#ifndef __SYSCOMMON_PROC_H__
+#define __SYSCOMMON_PROC_H__
+
+#include <unistd.h>
+
+int syscommon_proc_get_comm(pid_t pid, char *buf, int len);
+int syscommon_proc_get_cmdline(pid_t pid, char *buf, int len);
+int syscommon_proc_get_attr_current(pid_t pid, char *buf, int len);
+int syscommon_proc_is_app(pid_t pid);
+
+#endif /*__SYSCOMMON_PROC_H__ */
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdarg.h>
+
+#include "shared/log.h"
+#include "libsyscommon/proc.h"
+
+#define PATH_MAX 128
+#define NAME_MAX 64
+#define FORMAT_MAX 16
+
+static int proc_get_string(char *buf, int len, const char *pathfmt, ...)
+{
+ FILE *fp = NULL;
+ char path[PATH_MAX] = { 0 , };
+ char scanfmt[FORMAT_MAX] = { 0, };
+ va_list ap;
+ int ret = 0;
+
+ if (!buf || len < 0)
+ return -EINVAL;
+
+ va_start(ap, pathfmt);
+ ret = vsnprintf(path, PATH_MAX, pathfmt, ap);
+ va_end(ap);
+
+ if (ret < 0)
+ return -EIO;
+
+ if (ret >= PATH_MAX)
+ return -ENAMETOOLONG;
+
+ fp = fopen(path, "r");
+ if (!fp) {
+ _E("Failed to open %s, %m", path);
+ return -errno;
+ }
+
+ ret = snprintf(scanfmt, FORMAT_MAX, "%%%ds", len - 1);
+ if (ret < 0) {
+ fclose(fp);
+ return -EIO;
+ }
+
+ if (ret >= FORMAT_MAX) { /* impossible */
+ fclose(fp);
+ return -ERANGE;
+ }
+
+ errno = 0;
+ ret = fscanf(fp, scanfmt, buf);
+ if (ret != 1) {
+ fclose(fp);
+ return errno ? -errno : -EIO;
+ }
+
+ fclose(fp);
+
+ return 0;
+}
+
+int syscommon_proc_get_comm(pid_t pid, char *buf, int len)
+{
+ return proc_get_string(buf, len, "/proc/%d/comm", pid);
+}
+
+int syscommon_proc_get_cmdline(pid_t pid, char *buf, int len)
+{
+ return proc_get_string(buf, len, "/proc/%d/cmdline", pid);
+}
+
+int syscommon_proc_get_attr_current(pid_t pid, char *buf, int len)
+{
+ return proc_get_string(buf, len, "/proc/%d/attr/current", pid);
+}
+
+int syscommon_proc_is_app(pid_t pid)
+{
+ char attr[NAME_MAX] = { 0 ,};
+ size_t len = 0;
+ int ret = 0;
+
+ ret = syscommon_proc_get_attr_current(pid, attr, sizeof(attr));
+ if (ret != 0) {
+ _E("Failed to read privilege, %d", ret);
+ return -1;
+ }
+
+ len = strlen(attr) + 1;
+
+ if (!strncmp("System", attr, len))
+ return 0;
+
+ if (!strncmp("User", attr, len))
+ return 0;
+
+ if (!strncmp("System::Privileged", attr, len))
+ return 0;
+
+ return 1;
+}