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.