The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Executing shell program from a web page venkatritch Shell Programming and Scripting 5 06-14-2008 05:36 AM
Executing an .ec program in different informix versions matrixmadhan High Level Programming 0 05-21-2005 06:29 AM
executing the su command from a java program. shailendrat UNIX for Dummies Questions & Answers 1 03-24-2005 12:27 PM
executing a program within a program Gekko High Level Programming 4 06-27-2002 03:36 PM
Allowing a script to continue executing when a command hangs mkinney Shell Programming and Scripting 5 04-24-2002 01:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-17-2006
Crab Crab is offline
Registered User
  
 

Join Date: Sep 2006
Location: NewYork
Posts: 7
after executing execvp()... program hangs up

Hi ,

I m actually trying to implement pipes program,but after executing the execvp(),my program is getting hanged up

Actaully i m getting the desired output expected from execvp()...but once results are displayed on the output screen ,program is getting hanged up

values of variables before execution of this code

intial_command=more
argList[0]=more
argList[1]=NULL

child code:
{
close(0);
dup2(pipes[0][1],0);
close(pipes[0][0]);
execvp(intial_command,argList);
}
parent code:
printf("after child");
waitpid(pid,&status,0);

i guess since i have closed the stdin using close(0) thats y i m not able to input anythng even after execvp()...but as far my knowledge once the execvp() functions gets executed the child process gets terminated..so my program should resume to parent process

Last edited by Crab; 09-17-2006 at 09:47 PM..
  #2 (permalink)  
Old 09-17-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Code:
close(0);
dup2(pipes[0][1],0);
close(pipes[0][0]);open(0);
execvp(intial_command,argList);
Isn't that open(0) giving you any errors during compilation? The open syscall needs atleast two arguments.
  #3 (permalink)  
Old 09-17-2006
Crab Crab is offline
Registered User
  
 

Join Date: Sep 2006
Location: NewYork
Posts: 7
Sorry for the Typo...but i hav commented the open()

BTW it wasnt giving any system error...dunno kno how
  #4 (permalink)  
Old 09-21-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
execvp does not create a new process. It replaces the current process.

Proper sequence of events would be:
  • fork() to copy current process. The new process will be identical to the old one with one differnce -- the child and parent get different return values from fork().
  • Close and/or rearrange file descriptors as you please in the child code to make whatever the stdin/stdout/stderr/etc.
  • Call execvp in the child process

Maybye you're using fork already, but that code snippet doesn't show it..
Closed Thread

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 01:15 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