after executing execvp()... program hangs up


 
Thread Tools Search this Thread
Top Forums Programming after executing execvp()... program hangs up
# 1  
Old 09-17-2006
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 Smilie

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 10:47 PM..
This User Gave Thanks to Crab For This Post:
# 2  
Old 09-17-2006
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  
Old 09-17-2006
Sorry for the Typo...but i hav commented the open()

BTW it wasnt giving any system error...dunno kno how Smilie
# 4  
Old 09-21-2006
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Fork and Execvp Not Executing Bash Commands From C correctly.

I had been looking at page 75 of this online book: http://richard.esplins.org/static/downloads/linux_book.pdf I've used the system function in C to call bash commands before, but wanted to learn this way too. The solution in the book worked perfectly. However, I tried changing the simple "ls -l... (3 Replies)
Discussion started by: Azrael
3 Replies

2. Programming

Program Hangs

I have two programs, DriverScale.c and scale9.c. DriverScale.c calls scale 9.c which sends a W and a carraige return to the scale which SHOULD return the weight to DriverScale. However scale 9 hangs for at least 10 min, and then finally returns the weight. Compilation: ... (8 Replies)
Discussion started by: Meow613
8 Replies

3. Programming

Error in executing the C program

Hello Friends, I have written a code for the unisex bathroom which makes a policy that when a woman is in the bathroom only other women may enter, but not men, and vice versa. This program consists of four functions which a user defines but these functions are not properly working while... (4 Replies)
Discussion started by: Ravi Tej
4 Replies

4. Shell Programming and Scripting

How to display a message if program hangs(takes too long)

I have a ksh script (script1) that calls another ksh script (script2). If script2.ksh hangs or takes too long to execute I want script1.ksh to kill the call to script2.ksh and instead just display "Script2 can't run right now". Could someone help me with coding this? (1 Reply)
Discussion started by: mrskittles99
1 Replies

5. UNIX for Dummies Questions & Answers

executing a different program

What system calls or commands do I need to use in order to execute a different program from an already running process? (1 Reply)
Discussion started by: justOne21
1 Replies

6. Shell Programming and Scripting

Executing WIN32OLE program

Hello, Please help me out to execute this perl program: #!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... # get already active Excel application or open new my... (6 Replies)
Discussion started by: suvenduperl
6 Replies

7. Programming

popen hangs program during cmd execution

How can I get around this? when my program reaches the following popen job it halts the program until the ping/netstat/ipconfig/traceroute is completed then resume to the rest of the program... FILE *in; extern FILE *popen(); char buff; char newline; char nstat; char nping; ... (5 Replies)
Discussion started by: Jess83
5 Replies

8. Shell Programming and Scripting

Executing a Java Program

I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

9. Programming

executing a program within a program

Read the title: how do i do it? (4 Replies)
Discussion started by: Gekko
4 Replies

10. Shell Programming and Scripting

Allowing a script to continue executing when a command hangs

Hello all, I'm writing a script in c-shell that, among other things, queries information from another system. Is there a graceful way I can continue execution of the script if that query command(rup) causes the script to hang? Thanks much! (5 Replies)
Discussion started by: mkinney
5 Replies
Login or Register to Ask a Question