Lines Matching refs:pid

56 static int get_process_state(pid_t pid) {  in get_process_state()  argument
62 assert(pid >= 0); in get_process_state()
65 if (pid == 0 || pid == getpid_cached()) in get_process_state()
68 p = procfs_file_alloca(pid, "stat"); in get_process_state()
88 int get_process_comm(pid_t pid, char **ret) { in get_process_comm() argument
93 assert(pid >= 0); in get_process_comm()
95 if (pid == 0 || pid == getpid_cached()) { in get_process_comm()
105 p = procfs_file_alloca(pid, "comm"); in get_process_comm()
127 pid_t pid, in get_process_cmdline_nulstr() argument
149 p = procfs_file_alloca(pid, "cmdline"); in get_process_cmdline_nulstr()
166 r = get_process_comm(pid, &comm); in get_process_cmdline_nulstr()
185 int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **ret) { in get_process_cmdline() argument
190 assert(pid >= 0); in get_process_cmdline()
207 int full = get_process_cmdline_nulstr(pid, max_columns, flags, &t, &k); in get_process_cmdline()
401 int is_kernel_thread(pid_t pid) { in is_kernel_thread() argument
409 …if (IN_SET(pid, 0, 1) || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a ker… in is_kernel_thread()
411 if (!pid_is_valid(pid)) in is_kernel_thread()
414 p = procfs_file_alloca(pid, "stat"); in is_kernel_thread()
459 int get_process_capeff(pid_t pid, char **ret) { in get_process_capeff() argument
463 assert(pid >= 0); in get_process_capeff()
466 p = procfs_file_alloca(pid, "status"); in get_process_capeff()
475 static int get_process_link_contents(pid_t pid, const char *proc_file, char **ret) { in get_process_link_contents() argument
481 p = procfs_file_alloca(pid, proc_file); in get_process_link_contents()
487 int get_process_exe(pid_t pid, char **ret) { in get_process_exe() argument
491 assert(pid >= 0); in get_process_exe()
493 r = get_process_link_contents(pid, "exe", ret); in get_process_exe()
506 static int get_process_id(pid_t pid, const char *field, uid_t *ret) { in get_process_id() argument
514 if (pid < 0) in get_process_id()
517 p = procfs_file_alloca(pid, "status"); in get_process_id()
549 int get_process_uid(pid_t pid, uid_t *ret) { in get_process_uid() argument
551 if (pid == 0 || pid == getpid_cached()) { in get_process_uid()
556 return get_process_id(pid, "Uid:", ret); in get_process_uid()
559 int get_process_gid(pid_t pid, gid_t *ret) { in get_process_gid() argument
561 if (pid == 0 || pid == getpid_cached()) { in get_process_gid()
567 return get_process_id(pid, "Gid:", ret); in get_process_gid()
570 int get_process_cwd(pid_t pid, char **ret) { in get_process_cwd() argument
571 assert(pid >= 0); in get_process_cwd()
573 if (pid == 0 || pid == getpid_cached()) in get_process_cwd()
576 return get_process_link_contents(pid, "cwd", ret); in get_process_cwd()
579 int get_process_root(pid_t pid, char **ret) { in get_process_root() argument
580 assert(pid >= 0); in get_process_root()
581 return get_process_link_contents(pid, "root", ret); in get_process_root()
586 int get_process_environ(pid_t pid, char **ret) { in get_process_environ() argument
593 assert(pid >= 0); in get_process_environ()
596 p = procfs_file_alloca(pid, "environ"); in get_process_environ()
631 int get_process_ppid(pid_t pid, pid_t *ret) { in get_process_ppid() argument
637 assert(pid >= 0); in get_process_ppid()
639 if (pid == 0 || pid == getpid_cached()) { in get_process_ppid()
645 if (pid == 1) /* PID 1 has no parent, shortcut this case */ in get_process_ppid()
648 p = procfs_file_alloca(pid, "stat"); in get_process_ppid()
685 int get_process_umask(pid_t pid, mode_t *ret) { in get_process_umask() argument
690 assert(pid >= 0); in get_process_umask()
693 p = procfs_file_alloca(pid, "status"); in get_process_umask()
702 int wait_for_terminate(pid_t pid, siginfo_t *status) { in wait_for_terminate() argument
705 assert(pid >= 1); in wait_for_terminate()
713 if (waitid(P_PID, pid, status, WEXITED) < 0) { in wait_for_terminate()
739 int wait_for_terminate_and_check(const char *name, pid_t pid, WaitFlags flags) { in wait_for_terminate_and_check() argument
744 assert(pid > 1); in wait_for_terminate_and_check()
747 r = get_process_comm(pid, &buffer); in wait_for_terminate_and_check()
749 … log_debug_errno(r, "Failed to acquire process name of " PID_FMT ", ignoring: %m", pid); in wait_for_terminate_and_check()
756 r = wait_for_terminate(pid, &status); in wait_for_terminate_and_check()
793 int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) { in wait_for_terminate_with_timeout() argument
814 if (waitid(P_PID, pid, &status, WEXITED|WNOHANG) == 0) { in wait_for_terminate_with_timeout()
815 if (status.si_pid == pid) { in wait_for_terminate_with_timeout()
842 void sigkill_wait(pid_t pid) { in sigkill_wait() argument
843 assert(pid > 1); in sigkill_wait()
845 (void) kill(pid, SIGKILL); in sigkill_wait()
846 (void) wait_for_terminate(pid, NULL); in sigkill_wait()
849 void sigkill_waitp(pid_t *pid) { in sigkill_waitp() argument
852 if (!pid) in sigkill_waitp()
854 if (*pid <= 1) in sigkill_waitp()
857 sigkill_wait(*pid); in sigkill_waitp()
860 void sigterm_wait(pid_t pid) { in sigterm_wait() argument
861 assert(pid > 1); in sigterm_wait()
863 (void) kill_and_sigcont(pid, SIGTERM); in sigterm_wait()
864 (void) wait_for_terminate(pid, NULL); in sigterm_wait()
867 int kill_and_sigcont(pid_t pid, int sig) { in kill_and_sigcont() argument
870 r = RET_NERRNO(kill(pid, sig)); in kill_and_sigcont()
875 (void) kill(pid, SIGCONT); in kill_and_sigcont()
880 int getenv_for_pid(pid_t pid, const char *field, char **ret) { in getenv_for_pid() argument
887 assert(pid >= 0); in getenv_for_pid()
891 if (pid == 0 || pid == getpid_cached()) { in getenv_for_pid()
908 if (!pid_is_valid(pid)) in getenv_for_pid()
911 path = procfs_file_alloca(pid, "environ"); in getenv_for_pid()
948 int pid_is_my_child(pid_t pid) { in pid_is_my_child() argument
952 if (pid <= 1) in pid_is_my_child()
955 r = get_process_ppid(pid, &ppid); in pid_is_my_child()
962 bool pid_is_unwaited(pid_t pid) { in pid_is_unwaited() argument
965 if (pid < 0) in pid_is_unwaited()
968 …if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be run… in pid_is_unwaited()
971 if (pid == getpid_cached()) in pid_is_unwaited()
974 if (kill(pid, 0) >= 0) in pid_is_unwaited()
980 bool pid_is_alive(pid_t pid) { in pid_is_alive() argument
985 if (pid < 0) in pid_is_alive()
988 if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */ in pid_is_alive()
991 if (pid == getpid_cached()) in pid_is_alive()
994 r = get_process_state(pid); in pid_is_alive()
1001 int pid_from_same_root_fs(pid_t pid) { in pid_from_same_root_fs() argument
1004 if (pid < 0) in pid_from_same_root_fs()
1007 if (pid == 0 || pid == getpid_cached()) in pid_from_same_root_fs()
1010 root = procfs_file_alloca(pid, "root"); in pid_from_same_root_fs()
1112 pid_t pid; in valgrind_summary_hack() local
1113 pid = raw_clone(SIGCHLD); in valgrind_summary_hack()
1114 if (pid < 0) in valgrind_summary_hack()
1116 else if (pid == 0) in valgrind_summary_hack()
1119 log_info("Spawned valgrind helper as PID "PID_FMT".", pid); in valgrind_summary_hack()
1120 (void) wait_for_terminate(pid, NULL); in valgrind_summary_hack()
1216 pid_t original_pid, pid; in safe_fork_full() local
1256 pid = raw_clone(SIGCHLD| in safe_fork_full()
1260 pid = fork(); in safe_fork_full()
1261 if (pid < 0) in safe_fork_full()
1263 if (pid > 0) { in safe_fork_full()
1266 log_debug("Successfully forked off '%s' as PID " PID_FMT ".", strna(name), pid); in safe_fork_full()
1276 … r = wait_for_terminate_and_check(name, pid, (flags & FORK_LOG ? WAIT_LOG : 0)); in safe_fork_full()
1284 *ret_pid = pid; in safe_fork_full()
1426 pid_t pid; in namespace_fork() local
1437 …s, n_except_fds, flags & ~(FORK_WAIT|FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_NULL_STDIO), &pid); in namespace_fork()
1443 *ret_pid = pid; in namespace_fork()
1447 … r = wait_for_terminate_and_check(inner_name, pid, FLAGS_SET(flags, FORK_LOG) ? WAIT_LOG : 0); in namespace_fork()