fork problem

hi guys,

I am trying to figure out this problem for days and have not found yet.
It literally drives me crazy.

the problem is
when I do

(this is a code snippet.)
int my system(char **argv){

.......MORE CODE HERE.......

switch(pid = fork())
{
case -1:
perror(.........);
exit(1);
break;

case 0:
tokenize(buffer, &argv[0]);
signal(SIGINT,SIG_DFL);
signal(SIGOUT,SIG_DFL);
fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,0644);
dup2(fd,STDOUT_FILENO);
close(fd);
execv(argv[0],&argv[1]);
perror("child fork error");
break;
}

the argv's value had been changed. the result was displaying "child fork error : no child process".
the function tokenize gets command(which is a variable named buffer) and arguments(defined char **argv). then argv will be set with strings that i entered which were argv[0] = "/bin/ls" argv[1] = "ls" argv[2]=NULL
i have checked it displayed the data as it should be when i put an code line before fork().

and also i tried with this code, setting the data by hardcoding.

switch(pid = fork())
{
case -1:
perror(.........);
exit(1);
break;

case 0:
argv[0]="/bin/ls";
argv[1]="ls";
argv[2]="-al";
argv[3]=NULL;
filename="a.out";
signal(SIGINT,SIG_DFL);
signal(SIGOUT,SIG_DFL);
fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,0644);
dup2(fd,STDOUT_FILENO);
close(fd);
execv(argv[0],&argv[1]);
perror("child fork error");
break;
}

then it worked fine.
any help please.
Topic archived. No new replies allowed.