Sponsored Content
Full Discussion: pipe-fork-execve
Top Forums Programming pipe-fork-execve Post 302267931 by xtremejames183 on Sunday 14th of December 2008 05:34:24 PM
Old 12-14-2008
pipe-fork-execve

Hi everyone , after a pipe() system call i've forked and entred into the child process to execve a shell script .the problem here is that when the execve sys call fail , i want to send the error code (eg errno) to the parent process using the pipe writer side p[1] , there is nothing received in the reader-side of the parent process , checkout:

int p[2];
pid_t pid;

pipe(p);
pid = fork();
if( pid < 1 ){
/* bla bla */
close(p[0]);
close(p[1]);
return ;
}
if( pid == 0 ){
close(p[0]);


fcntl(p[1],F_SETFD,0) ; /* do not close on exec */

execve("/bin/sh",arg,env);
int err = errno;
write(p[1],&err,sizeof(int)); /* why there is nothing received in my parent process */
_exit(127);
}

/* parent process */
close(p[1]);
if( read(p[0],&code,sizeof(int) ) < 0){
perror("nothing received");
/* this is true even if the execve() fail and there is something sent.. why */
}

Any one can help..thanks

Last edited by xtremejames183; 12-14-2008 at 07:51 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

execve to execute a program

I tried using the following code to execute a program but it doesnt seems to be working .. I would like to know whats wrong wit it . execve("/bin/cat", "words", NULL); (0 Replies)
Discussion started by: winsonlee
0 Replies

2. Programming

C++ How to use pipe() & fork() with stdin and stdout to another program

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies

3. Programming

md5sum and execve

Hello there! Is there a way to use execve() to run md5sum function? for example execve("md5sum <filename>, NULL,NULL);" thanx! (2 Replies)
Discussion started by: nicos
2 Replies

4. Programming

fork&pipe "interpretting" shell - problem

hello everybode.Got some sort of "problems" with this stuff; well this is a program int main() { int Pipe; int origStdin, origStdout; int childPID; origStdin = dup(0); origStdout = dup(1); pipe(Pipe); if( (childPID = fork()) < 0 ) { perror(... (2 Replies)
Discussion started by: IdleProc
2 Replies

5. Programming

execve notification in user mode under Linux

Hi, I'm writing a monitor program that can be notified once a process makes an execve system call and then stop that process for examining before it starts to run the new code. I know I can ptrace a process to achieve this, but I do not want to ptrace every process in the system. Is it possible?... (1 Reply)
Discussion started by: aaron.lwe
1 Replies

6. UNIX for Dummies Questions & Answers

Conserving processes: execve() vs fork()

Disclaimer: This is just a rainy day experiment. There is no expected "goal" other than to understand UNIX better. After reading about fork and exec, my understanding is that forking, as the UNIX shell does by design, consequentially may sacrafice some speed versus an approach that runs in... (1 Reply)
Discussion started by: uiop44
1 Replies

7. Programming

Newbie question on exec,fork, wait,pipe C

Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine. So, i want to... (1 Reply)
Discussion started by: Cuervo
1 Replies

8. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

9. Programming

Permission error while using execve..

Hi, I have the following scenario.. 1) I have a binary which i launch from command line. It executes fine. 2) But when I launch it from another file using execve command, it gives a message that it is not able to access a shared object ".so" in /usr/bin (message is "Permission... (4 Replies)
Discussion started by: sathish1000
4 Replies

10. UNIX for Beginners Questions & Answers

One parent, multiple children pipe with fork()

The task I have to do is something along the lines "I receive some input and based on the first character I send it through pipe to one of the children to print". The scheme it is based on is 1->2; 1->3; 1->4; 2 will print all the input that starts with a letter, 3 will print all the input that... (2 Replies)
Discussion started by: Ildiko
2 Replies
vfork(2)							System Calls Manual							  vfork(2)

Name
       vfork - spawn new process in a virtual memory-efficient way

Syntax
       pid = vfork()
       int pid;

Description
       The  can  be used to create new processes without fully copying the address space of the old process, which is inefficient in a paged envi-
       ronment.  It is useful when the purpose of would have been to create a new system context for an The system call differs from in  that  the
       child borrows the parent's memory and thread of control until a call to or an exit (either by a call to or abnormally.)	The parent process
       is suspended while the child is using its resources.

       The system call returns a value of zero (0) in the child's context and, later, the pid of the child in the parent's context.

       The system call can normally be used just like It does not work, however, to return while running in the childs context from the  procedure
       which  called because the eventual return from would then return to a nonexistent stack frame.  Be careful, also, to call _exit rather than
       exit if you cannot call because exit will flush and close standard I/O channels and thereby cause problems in the parent process's standard
       I/O data structures.  Even with it is wrong to call exit, because buffered data would then be flushed twice.

Restrictions
       To avoid a possible deadlock situation, processes which are children in the middle of a are never sent SIGTTOU or SIGTTIN signals.  Rather,
       output or ioctls are allowed, and input attempts result in an end-of-file indication.

Diagnostics
       Same as for

See Also
       execve(2), fork(2), sigvec(2), wait(2)

																	  vfork(2)
All times are GMT -4. The time now is 09:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy