The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 05-23-2007
ku@ntum ku@ntum is offline
Registered User
 

Join Date: May 2007
Posts: 4
Not working

The dup2() system call takes the oldfd as first argument. According to that,

int in = open(con, O_RDWR);
dup2(in, 1);
dup2(in, 2);


However I have change the code to

int main(int argc, char **args)
{
char *con = args[1];
printf("\nStart demonizing ...\n");
int i = fork();
if (i == 0)
{
close (0);
close (1);
close (2);
setsid();

int j = fork();
if (j == 0)
{
setsid();
int in = open(con, O_RDWR);
dup2(in, 1);
dup2(in, 2);

char tmp[100];
strcpy(tmp, "Hello World");

printf("\n input :");

gets(tmp);

printf("\n output : %s\n", tmp);
}
exit(0);
}
}


But the problem remains. The same. Please help.
Reply With Quote