exec + fork

closed account (Nwb4iNh0)
What will be the result of this code?
Explain this line (exec ("/usr/bin/gedit"))

1
2
3
4
5
6
7
8
9
10
11
12
  int main () 
{
int p;
p = fork ();
if (p ==0) {
printf("child");
exec ("/usr/bin/gedit");
}

printf ("parent");
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
int main () 
{
int p;
p = fork ();    // clone the current process.  When it returns there are two processes running the code
if (p ==0) {    // fork() returns 0 to the "child" process. 
printf("child");  // Let the user know that the child is doing something.
exec ("/usr/bin/gedit");   // replace the current process (the child) with the named command. So this runs /usr/bin/gedit
}
// If you get here, you're the parent process
printf ("parent");
return 0;
}
closed account (Nwb4iNh0)
thanks for reply , but what does this line do here , and what this code print out on the screen?
 
exec ("/usr/bin/gedit");
> and what this code print out on the screen?
ah, programming without a monitor, those were the days
closed account (Nwb4iNh0)
@ne555 what you mean??
That line executes the program /usr/bin/gedit. What does gedit do? I have no idea. Type "man gedit" to find out.
Topic archived. No new replies allowed.