How to launch a new process


 
Thread Tools Search this Thread
Top Forums Programming How to launch a new process
# 1  
Old 05-05-2008
How to launch a new process

Hi, I have a situation where a C main program needs to call another C main program, my background is mostly Windows and I'm new to UNIX programming. I've read about system(), fork(), and exec() and I'm a little confused as to what the sequence of steps should be to launch another process. By the way the parent program would have to suspend execution until the child program returns and parent program would need to read the return or exit code of the child program. Thank you in advance for your help. Smilie

Last edited by hr94131; 05-05-2008 at 01:48 PM..
# 2  
Old 05-05-2008
Should your program 1 run, while programm 2 is running? -> fork(), exec()

Else use system(), you can call any program through it.
# 3  
Old 05-05-2008
The sequence is pipe() / fork() / exec() / waitpid(). Last call reads the exit status of the child process. Use of system() is discouraged as it's costly and resource intensive.
# 4  
Old 05-05-2008
system() costs mainly the memory for a shell instance. It's secure when the programmer considers the environement (variables) to be unreliable/hostile.

One has to consider what's more important: simplicity of code (system()) or efficiency (fork(), exec(), ...)
# 5  
Old 05-05-2008
Last time I checked system() was deprecated in that it uses /bin/sh -c and is a security risk due to set(u|g)id privilege escalation and environment manipulation attacks.

There's a good case that spawning a shell to execute a command is not a good idea (as shamrock noted) if a simple exec will suffice.
# 6  
Old 05-05-2008
Hi, thank you all for your quick reply.
Hec
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Install + launch java

Hi I want to write a very short bash script for doing the following action (on Ubuntu): First, install java Second, launch at a specific time (e.g. 4.30 pm) a java ANT program. How can I do this? (3 Replies)
Discussion started by: Helveticus
3 Replies

2. Shell Programming and Scripting

Launch Script

Hi all! I just got done writing a script. The problem Im running into is I have to lanuch the script with: sh SCRIPT.sh Is there a way to launch it with by just entering SCIPT into the shell? (3 Replies)
Discussion started by: Grizzly
3 Replies

3. Linux

Can't launch firefox

Hi all, I installed RHEL on my machine and realized that firefox browser was not included at installation. I went back and added it using the Add or Remove Packages by inserting the dvd I used during installation. The icon is there but for some reason I cannot lauch. Nothing returns when I... (12 Replies)
Discussion started by: jxh461
12 Replies

4. UNIX for Dummies Questions & Answers

How to launch Eclipse in Solaris 10

Hi people, i just installed Eclipse on my Solaris terminal and i can't seem to run it. Currently i am using the SSH Client software to go to my Unix console.I tried to run the command "eclipse -vm <path of java hre>" as directed however i still can't run the application. My Command prompt is... (5 Replies)
Discussion started by: wilsontan
5 Replies

5. UNIX for Advanced & Expert Users

Launch veritas netbackup

Hello - I already have Veritas netbackup installed on Mac OS. But I am not able to find the daemon name for running the backup. Does anyone know How to run netbackup? Thank you! (3 Replies)
Discussion started by: panchpan
3 Replies

6. UNIX for Advanced & Expert Users

launch a command only if

Hi! I would launch this command: tar -cvvf logswitch.tar `find *.log* -mtime +5` --remove-files only if find *.log* -mtime +5 find some files. Thanks in advance. (10 Replies)
Discussion started by: Minguccio75
10 Replies

7. UNIX for Dummies Questions & Answers

how to launch program though telnet

I have launched telnet on nt and have connected to a unix server, I'm trying to run a program on the unix server which will launch a gui, but when I try to launch it I get the message "display not set\n" "By default set it to 0.0" I can sit down at the unix machine and launch the program with... (3 Replies)
Discussion started by: cbachman
3 Replies

8. UNIX for Dummies Questions & Answers

how to Launch an independent process.

Hello, I needed a help please... I have an application which launches process. For this i am using fork and execv method calls. By doing this my launched process are now child process of the parent process(launching process). I dont want this to happen, i want the process that is launched to... (1 Reply)
Discussion started by: deepthi
1 Replies

9. Programming

How do you launch an .exe from my app?

Hello all - I'm writing an app that needs to have another program running BEFORE I fire up my application. The .exe resides on another computer - not on the computer that my app is running on. This computer is running Tru64 Digital Unix 4.0F The application that I wrote was built using... (1 Reply)
Discussion started by: kapolani
1 Replies

10. Shell Programming and Scripting

launch & monitor process on remote host

Hi, I am working on HPUX11 systems. I intend to achieve following: Need to write a shell script that will launch a program on remote UNIX machine. It will be gr8 if in addition, the remote process can be monitored using some feedback. I donno how to use rsh / ssh for this. (specifying... (1 Reply)
Discussion started by: mrx
1 Replies
Login or Register to Ask a Question