alternatives of exec() system function

Hi ,

Can anybody name any System Function in C/C++ for Sun-Solaris (unix) platform which can serve the alternative of execl() system function.

Actually I am calling a fork-execl() pair and then making an interprocess communication between these two(parent-child process). But the problem is that somewhere in exec() function which is working on some machines and failing on a few machines.

So anybody if have any alternative to exec() or fork()-exec() pair of system function questions then please reply.

Regards,
Raj Kumar Arora

fork and exec are two of the most fundamental calls on a UNIX system, if these are failing the system won't work.

Any alternative, such as "system()" or "popen()" will call fork()/vfork() and exec(), there is not really any other portable way to start a new process and launch a new program in it.

I suggest the errors are in the usage or understanding of what these calls do.

Admittedly, Linux has clone() but that's another story.

Thanks porter for your reply. The problem is not exactly in usage because it is running at few machines too. It may be some sort of environment or previledges problem. Actually now the situation is that I am trying to do that using Multithreading. I am creating two threads.

I needed to call an executable with some arguments in the function body for second thread. For that I am using system() call.

The problem is that :-

  1. system() function call is not allowing any further arguments to executable being called as execl() would if I was using a fork()-execl() pair in case of Multiprocessing.

  2. I need alternative to system() because system is also creating a new process. And I dont want to create a new process in a thread.

Regards,
Raj Kumar Arora

The function system() takes a string which will be parsed by the shell, this can have as many arguments as the system will permit.

Under UNIX, the only way you can run a program is by "exec" which replaces the current program image with the new program.

If you want your program to continue running you have to call fork() or vfork() to create a new process, tough, but that is UNIX.

Yes, threads and fork can be a nightmare, what exactly is the problem? If it's resource contention/locking I suggest you have a look at "pthread_atfork()".

If you need to spawn a new process from a multithreaded program you have no options other than

(a) using fork/vfork
(b) calling a a function that wraps them up
(c) use IPC to talk to another program to create the new process