Results 1 to 5 of 5
is there any change for fork() to change currently saved value in a variable pointer.(mainly string).
i ran into this problem, every after forking the value saved in a string ...
- 08-30-2009 #1Just Joined!
- Join Date
- Aug 2009
- Posts
- 6
forking.
is there any change for fork() to change currently saved value in a variable pointer.(mainly string).
i ran into this problem, every after forking the value saved in a string pointer or array whatever has been changed.
ex) argv[0] = "/bin/ls"
after forking
the value changed something like "/bin"+random symbols or just random symbols.
- 08-30-2009 #2
Could we see some code?
I tried to do something simple to duplicate this problem but couldn't make it appear.
- 08-30-2009 #3Just Joined!
- Join Date
- Aug 2009
- Posts
- 6
(please help) 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.
- 09-11-2009 #4Just Joined!
- Join Date
- Mar 2008
- Location
- Chennai, India
- Posts
- 26
1 .
tokenize(buffer, &argv[0]);
this should have been tokenize(buffer, &argv[1]);
let us assume your o/p file name is a.out then:
argv[0] is a.out.
argv[1] is the parameter you are looking for.
the command line arguments are numbered starting from 0, and the executable is referred by argv[0]
2.
thats what you did in the second case.
- 09-11-2009 #5Just Joined!
- Join Date
- Dec 2007
- Location
- Bangalore >> India
- Posts
- 28
Yes , sarma is rite


Reply With Quote
