alternatives of exec() system function


 
Thread Tools Search this Thread
Top Forums Programming alternatives of exec() system function
# 1  
Old 01-03-2008
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
# 2  
Old 01-03-2008
Quote:
Originally Posted by Raj Kumar Arora
So anybody if have any alternative to exec() or fork()-exec() pair of system function questions then please reply.
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.
# 3  
Old 01-03-2008
Quote:
Originally Posted by porter
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
# 4  
Old 01-03-2008
Quote:
Originally Posted by Raj Kumar Arora
And I dont want to create a new process in a thread.
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

2. Programming

[C] exec system call

Hi again ;) Now I want to make a program that will execute the programs with exec, asking the user if he wants the program to run in background or foreground. scanf("%c",&caracter); if (caracter=='y'){ printf("Has decidido ejecutarlo en background\n"); if((pid=fork())==0) {// fork para... (3 Replies)
Discussion started by: lamachejo
3 Replies

3. UNIX for Dummies Questions & Answers

Using system function in C

Hi Guys , I want to use system function in C to do the following work. cp <file1> <file2> and then ><file1> e,g cp \var\log\cpm_cpmd_1.log.1 \var\log\cpm_cpmd_1.log.2 and then >\var\log\cpm_cpmd_1.log.1 1. g_config_info.cpmm_config.cpm_log_path=\var\log\ 2. ... (3 Replies)
Discussion started by: meet123321
3 Replies

4. Shell Programming and Scripting

Perl variables in exec or system

I am new in Perl. I am working in simple script and the varibles are working well outside the exec or system command. but they don't work as parameters to exec or system command. The script is attached. please help. (8 Replies)
Discussion started by: ahmed_zaher
8 Replies

5. Shell Programming and Scripting

How to execute piped command using exec or system

Hi All, I want to execute a piped command like 'ls /opt | grep xml' using array as parameters list. How can I do that? (2 Replies)
Discussion started by: bharadiaam
2 Replies

6. Programming

Runtime.getSystem.exec() function waits for child

Runtime.getSystem.exec() waits for child process to complete .. I do not want to wait for the child process to complete ..what is the option which has to be used ? (2 Replies)
Discussion started by: shafi2all
2 Replies

7. UNIX for Advanced & Expert Users

exec to call specific function in C prog

I would like to call a particular function in a C program using execl(). Is this possible using execl or anyother function ? Thanks (2 Replies)
Discussion started by: vpraveen84
2 Replies

8. Shell Programming and Scripting

How can I execute own ksh function in find -exec

Hi, I wrote a smiple ksh function send_notification() { ... } and want to execute it on each file, matched by the find command. I tried: find / -name "*.err" -mtime -8 -exec send_notification {} \; but it doesn't work. What should I do? I work in ksh on Hp-Ux. Regards, Pit (11 Replies)
Discussion started by: piooooter
11 Replies

9. UNIX for Advanced & Expert Users

Alternatives to set the system date ??

Hi all, I need to syncronize a Solaris client with a QNX Server, modifying the client date, I need any alternative to set the sistem date (client Solaris) but i can't use commands date -a XXX (XXX are the time in seconds) and can't use rdate and ntp. How can I do It? :confused: (2 Replies)
Discussion started by: ulisses0205
2 Replies

10. Programming

exec() system call

hi there, i was reading about the exec() function. and if i m not wrong, exec() kills your present process and starts a new process in its place. the process id remains the same. then it says if exec is successful the text data and stack are overlayed by new file! - i dont get this part "only... (2 Replies)
Discussion started by: a25khan
2 Replies
Login or Register to Ask a Question