//fork하고
// 자식 프로세스면 출력을 닫은 뒤 userlist file을 생성
// 그곳에 who하는 프로그램.
// close(1)을하면 stdout이 닫히고,
// fd를 하면 빈 곳에 연결 되니까 1로 연결
// who의 결과가 userlist로 out된다.
#include <stdio.h>
main()
{
int pid;
int fd;
printf("about to run who into a file\n");
if((pid =fork()) == -1)
{
perror("fork");
exit(1);
}
if (pid == 0)
{
close(1);
fd = creat("userlist",0644);
execlp("who","who",NULL);
perror("execlp");
exit(1);
}
if(pid!=0)
{
wait(NULL);
printf("done running who. results in userlist\n");
}
}