
1. # pstree
2. # ps -ef |grep <进程名>
在显示的输出中,第三列就是该进程的父进程PID,然后可以再使用ps命令来查看父进程的名称
# ps -ef |grep <父进程PID>
这应该就是你想要的结果吧?
#include <stdio.h>#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
int main()
{
int pipe_fds[2]
int pid
if(pipe(pipe_fds))
{
fprintf(stderr,"pipe error!\n")
return -1
}
if((pid = fork())<0)
{
fprintf(stderr, "fork error!\n")
return -1
}
if(pid == 0)
{
char buf[20] = {0}
int n,i
close(pipe_fds[1])
read(pipe_fds[0],buf,sizeof(buf))
n=atoi(buf)
for(i=1i<=ni++)
{
if(i%10 == 0)
printf("\n")
printf("%d\t",i)
}
close(pipe_fds[0])
}
else
{
int m
char bf[20] = {0}
close(pipe_fds[0])
printf("the child pid:%d\n",pid)
printf("please input number:")
scanf("%d",&m)
printf("\n")
sprintf(bf,"%d",m)
write(pipe_fds[1],bf,sizeof(bf))
wait(NULL)
printf("child complete!\n")
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)