#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <time.h>
#include <unistd.h>
void main()
{
pid_t pid;
pid = fork();
if(pid < 0 )
{
perror("fork error!\n");
strerror(1);
}
else if(pid == 0)
{
printf("fork sub process success!\n");
while(1)
{
//printf("sub process is running! uid is %d, gid = %d\n",getuid(),getgid());
sleep(3);
}
}
{
printf("sub process is running! uid is %d, pid = %d\n",getuid(),getpid());
printf("parent is over\n");
/*exec shutdown sub process ,so only one exec command is executed.*/
execlp("ls","ls","-l",(char *)0);
execlp("date","date",(char *)0);
exit(0);
}
}
#include <stdlib.h>
#include <error.h>
#include <time.h>
#include <unistd.h>
void main()
{
pid_t pid;
pid = fork();
if(pid < 0 )
{
perror("fork error!\n");
strerror(1);
}
else if(pid == 0)
{
printf("fork sub process success!\n");
while(1)
{
//printf("sub process is running! uid is %d, gid = %d\n",getuid(),getgid());
sleep(3);
}
}
{
printf("sub process is running! uid is %d, pid = %d\n",getuid(),getpid());
printf("parent is over\n");
/*exec shutdown sub process ,so only one exec command is executed.*/
execlp("ls","ls","-l",(char *)0);
execlp("date","date",(char *)0);
exit(0);
}
}