[英]Language C - Get the Process owner
I have to use the EXEC family to find the process owned (the user) and write it in a file. 我必须使用EXEC家族来查找所拥有的进程(用户)并将其写入文件中。
CODE: 码:
sprintf(buffer, "%d", getpid());
if ((pid = fork()) == -1)
exit(EXIT_FAILURE);
else if (pid == 0)
{
dup2(fd,STDOUT_FILENO);
dup2(fd,STDERR_FILENO);
// function that Write in the file
fdprintf(fd, "\n%s %s%d secondes %s\n", adornment, toShow, sec, adornment);
if (execlp("ps", "u", buffer, NULL) == -1)
show_err("Exelp Error\n");
}
else
{
wait(NULL);
fdprintf(fd, "%s %s%d secondes %s\n", adornment, toShow, sec, adornment);
close(fd);
}
any help is appreciated ! 任何帮助表示赞赏! Thanks
谢谢
What you are doing is the thedailywtf equivalent of getuid(2)
. 您正在执行的是
getuid(2)
的thedailywtf等效项。 If you want to get the login name, you can use getpwuid(3)
. 如果要获取登录名,可以使用
getpwuid(3)
。
getppid() getppid()
get parent pid, check the man pages for more info 获取父pid,请查看手册页以获取更多信息
pid_t parent_pid = getppid();
最后,我使用EXECVE ...对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.