The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
exec to call specific function in C prog vpraveen84 UNIX for Advanced & Expert Users 2 06-03-2008 03:55 PM
how to call awk in a csh Program bikas_jena Shell Programming and Scripting 5 11-25-2007 05:24 AM
exec() system call a25khan High Level Programming 2 02-03-2004 12:06 AM
need to restrict program exec and running hachik UNIX for Dummies Questions & Answers 1 09-16-2002 10:45 AM
Exec. commands in python J.P Shell Programming and Scripting 1 12-19-2001 04:56 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2009
suryashikha suryashikha is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 5
How to run two commands from a exec call in a c program

Hi,

I have to run two commands one after another from a c program. How can i do this with exec system calls. i tried giving them as argument toexecv but it is not working.please help


thanks
  #2 (permalink)  
Old 10-30-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,944
From the man page of exec(3):
Quote:
The exec() family of functions replaces the current process image with a new process image.
Means that as soon as the execv() is executed, the current process (your program) is completely replaced by the program you're starting. Any instructions left in the original program won't be executed.

If you want to just run a child process, use system(3)
  #3 (permalink)  
Old 10-30-2009
suryashikha suryashikha is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 5
I cannot use system as my program is setuid prgram. Basically i am trying to run two commands which require root privilegs from a set uid program . how can i run one command and then second command using exec system calls.
  #4 (permalink)  
Old 10-30-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,944
I'd think about why it's necessary to run that program as setuid root, and if that couldn't be accomplished by other means (eg. sudo) or by using a different approach using as few privileges as possible.

IF that isn't possible, you could simulate the system() call by using fork() and wait() (warning: the following is pseudo-code)
Code:
function my_system(command)
    pid = fork()
    if pid == 0 // child
        exec(command)
    else
        wait for pid to exit

my_system(command1);
my_system(command2);

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0