1. What is the difference between the system and exec family of functions?

2. I want to collect the output of the call from the system functions say. Say I execute this

system("date");

Now say I don't want it to display the output rather it give the output as an array of strings which I can try to analyze. Java has some functionality where it creates some Process instance and then get the input/outputstream which can be analyzed. I guess python/ruby/perl even bash shell scripting has similar facility where you type some command within `and ` that can be assigned to some variable to be analyzed later on. So something in this line of work. Is there any sort of functions other than those two mentioned above which can be used to have similar effects?

3. Why do we get only 2 processes after calling fork? I mean why they design it like that? Why can't we get a parent process and a couple of child processes? Why didn't they think of creating more than 2 processes?

1. exec gives you a lot more control, look in the man pages or use google and you will find all the different ways exec can be used.

2. Either redirect the output such as system("data >filename.txt") to a file or use pipes.

3. Why not? For each fork() you get a new process. Why would you want more than one process for each fork()? That would be just nuts. You can create as many processes as you want by calling fork() numerous times.

1. System runs the command and the parent process waits for it to finish. You still have the original process. Exec replaces the current process with a new process. The original process is lost.

2. popen might be what you're looking for.

3. I'd be guessing as to the exact reason, so I'll keep my thoughts to myself on this one.

commented: I forgot about that :) +27
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.