Programming :: Re-mapping Stdio For A Fork'd/exec'd Executable Doesn't Seem To Behave

Jan 27, 2011

I have a monitoring program ( GIT link to sourceforge ) which I'm trying to use to track when a child exits/dies/whatever. I'm calling fork(), then close for 0,1,2, and then opening /dev/null, monitored.stdout, and monitored.stderr as a replacement. I'm not sure if I've done something incorrect (perhaps I should use dup2 for explicit assignment?) but it appears that printf() messages are just being blackholed. I've tried setting the line buffering as a last ditch effort. On a different system, using code similar to the spawn_monitor() function, this appears to work fine, which makes me think I'm relying on some implementation specific detail.

Relevant function, for those who don't click links:


26 int spawn_monitored(char *argv[])
27 {
28 int exit = 0;
29 pid_t child;
30 const struct rlimit inf = {


View 14 Replies


Programming :: Fork/exec Versus Posix_spawn

Sep 30, 2010

Just coming over from Windows here... where I've been using "CreateProcess" which returns a value depending on whether the process was created successfully or not.

Now I'm trying to create a process on linux and I've been learning about fork/exec, and I've been struggling with the fact that there seems to be no easy way to know (within the original parent process) if exec succeeded or not. (without forcing the parent process to hang around polling it or something).

Anyway, I've now just discovered the posix_spawn function, and it seems exactly what I need. However I'm finding the documentation a little hard to understand. In particular, I can't find actual confirmation that it will definitely return an error if creating the process fails (like CreateProcess does on windows). So can anyone confirm that for me?

The text on the documentation states: "If posix_spawn() or posix_spawnp() fail for any of the reasons that would cause fork() or one of the exec family of functions to fail, an error value shall be returned as described by fork() and exec"

This makes me think it uses exec/fork under the hood, and so I wonder if it can be trusted..?

And also, most of the examples on the internet for creating processes use fork/exec, so I wonder if there is some catch with posix_spawn I haven't read about... (since it seems a much simpler way of doing things)

View 2 Replies View Related

Programming :: Passing Usb_dev_handle After Fork Exec?

Aug 19, 2010

I have been struggling with this for about a week now. I'm working with QuickUSB to send video streams to and from a device. I get the fastest results by fork()ing and exec()ing new processes everytime I run a pipeline, which works great when reading from files, but now i have to transition it so that i am reading/writing data over a QuickUSB bus. I have it working for each individual process, but i can't run multiple processes because it won't let me open the device. After looking through QuickUSB's API a little closer, i found that the QHANDLE type that they use to describe the usb device is actually just a usb_dev_handle *. From what i have found, this is an incomplete structure, so i am having trouble with opening it in the main process and passing it to each new process to write to it. I already have semaphores set up to prevent multiple processes using it at the same time. I just CANT find out how to utilize the same usb device between two process that are forked and exec. i also must do the exec() because otherwise my gtk and gstreamer fails for trying to share resources.

View 1 Replies View Related

Programming :: How To Make G++ Behave Like Gcc

Mar 15, 2010

I am compiling some c++ code trying to connect it with libi2cbrdg.a library where I have a lot of functions. So when I am doing this gcc -g rand.c -lasound -li2cbrdg -o rand.I don't have missed functions instead I have some other C/C++ connected errors, when I am using g++ compiler like this g++ -g rand.c -lasound -li2cbrdg -o does not see functions inside that library but everything fine with c++ code.How can I make g++ behave like gcc in this case?

View 2 Replies View Related

Programming :: Lost Gcc .bash_profile Paths - Error: "stdio.h: No Such File Or Directory Gcc Was Installed And Configured Correctly"

May 5, 2010

I tried compiling a simple Hello World with gcc but didn't have any luck. I got this message: Code: junk.c:1:19: error: stdio.h: No such file or directory gcc was installed and configured correctly at one point but I think I changed the the .bash_profile since then. I checked where stdio.h lives. The path is:


View 2 Replies View Related

Programming :: How To Use Globals When Using Fork

Sep 16, 2010

As part of my ongoing project I need to put together a messaging server of sorts. So far I have coded a server which accepts multiple connections, which then runs a function that will perform a task, see below.On this sever I have a global structure which is populated using the data found in a read() buffer. However with each fork() that runs the below function each process is handed a blank structure. How could I go about allowing each fork() child process access the same structure?

My code should hopefully show what I am trying to do?
Code: void listen_for_client(int sock)


View 5 Replies View Related

Programming :: Can't Run Second Child In C (Fork)

Apr 10, 2011

Now,I created one parent and two children. I must create some value as random in child1 and child1 has to send these values to child2.Child2 must read them.. now,I cant create some random values and i can send them.But child2 doesnt work. I have two functions. One them is writing, another one is reading. Child2 uses reading function,but it doesnt work (child2 cant call it, because writing function in endless loop) What i must do? I used wait,usleep... No way.. I attached my file and also there is code..

PHP Code: #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include <sys/types.h>

View 2 Replies View Related

Programming :: Creating Multiple Processes Using Fork

Oct 23, 2010

As an assignment i was doing a program to create two process using fork and pass messages between them using message queue.Did it worked well until my friend tried to copy it using scp.suddenly all hell broke loose as processes without ran syncronisation ie. in tech terms the process just wont wait wen a message queue is keeps on executing randomly.but after a reboot .. everything worked fine. until again i tried to do scp on my system on purpose. and again the program just went mad.

View 3 Replies View Related

Programming :: Why Fork Is Executing The Program Twice From Start

May 25, 2011

I am learning about OS and I wrote this simple forking program... Here's the code..

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>


How can it print the first statement, that is BEFORE the fork() statement twice?

I am running Natty 11.04 btw..

View 8 Replies View Related

Programming :: Understanding Pid() And Fork() Programming?

Mar 28, 2011

I have been doing programming since the last 5 years. however, i have used to cut and paste the template without knowing in depth since i am chasing the time to finish a certain project. The title above seems easy if we read the manual, its just that im kinda confuse just for a second. Hope you guys can help me to give a better understanding for me so that i can upgrade my knowledge.Well, during my normal practice cut and paste, i try to understand this code below :-

Code: pid_t pid;
if (pid < 0) {perror("Erro spawning process : "); exit(EXIT_FAILURE);}


View 4 Replies View Related

Programming :: Exec And Ssh : Command In Scripting?

Aug 4, 2010

I am a newbie, I am writing a script file to execute some programs.

# ! bin/ bash


echo "*************************************"
echo "*************************************"
#exec ssh automatix

problem 1 : I can ssh to the required space but after the terminal prompts me for password it stops ececuting the script.

problem 2: after performing the 'exec' command for the first time. its not executing anything after that line. is there any work around for this.

View 1 Replies View Related

Programming :: Fork()ing Multi Child Process In C - Stuck

May 12, 2011

i got basic knowledge about creating a single child from a parent using fork(). But when it comes into creating multiple children, i am simply stuck. I am trying to create two processes from a parent and it would wait for both two processes to finish. my attempt is as below


View 3 Replies View Related

Programming :: Bash Redirection With Exec: Specify Fd With Variable?

Feb 21, 2010

Within a bash script, I'm attempting to redirect file descriptors with exec, e.g. exec 3>&1 1>&2; however, I'd like to do something like exec $FD>&1 1>&2, which doesn't work because bash tries to execute the value of $FD. Various placements of eval fail, as well. Is there a way around this, or am I stuck hard-coding the descriptor?

View 3 Replies View Related

Programming :: Gdb Debugging Exec From Child Process?

Jul 14, 2011

Im using gdb for debugging my application.. I was able to debug child process(when fork comes) .. and in child process we have an exec call to .... So the problem is, when the control come to exec , the exec process is executing at a time... I could not debug the exec. process... error is stack curruption due to same frame So, is there any way to debug the exec process

View 1 Replies View Related

Programming :: Python's Thread & Fork Support Is Compared To Perl?

Mar 24, 2011

I'm wondering how python's thread & fork support is compared to perl? Which one is best option among Perl and Python

View 1 Replies View Related

Programming :: Fork() Copies The Address Space Of The Calling Process?

May 13, 2010

I know that fork() copies the address space of the calling process. Say, however, i have a linked list allocated. Will the list be copied over to the child process's space? If so, i would have to free them in the child process as well as the parent process, correct? Or will the variables be copied but not be pointing to any valid address? Or would it just kind of not do anything?example:

struct ll_ex {
struct ll_ex * next;


View 7 Replies View Related

Programming :: Fork() - Variable Values Between Child And Parent Process?

Feb 24, 2010


int main()
int pi;
int i=10;


Q 1. The value of the variable pid returned by the fork() function will be greater than 0 in the parent process and equal to zero in the child process? but during forking, there values are exactly copied so what's went wrong here?

Q 2. "changes to the variable in one process is not reflected in the other process" why it is so? >> Even if we have variable i declared as a pointer or a global it wont make a difference.


int main()
int i, pid;
printf("before fork i is %d


Q. Through this program it is clear that both process is using the data from the same location, so where's the original value is residing when the child process is in execution.?

View 6 Replies View Related

Programming :: `find . -exec' Handling Backticks In Bash

May 15, 2011

i had a problem with the find command in bash (which i deem is close enough to a promming language, if not please move this thread :P). i tried to reduce the command to the problem. i want the backticks, or $() for that matter; to be evaluated by -exec of find, not by bash. is that a caveat of find?


$ find testd -exec echo `basename {}` ; #confused me


edit: i found out whats causing this. `basename {}` gets evaluated by bash before find is invoked, returns {} and `find . -exec echo {} ;" is run. now my question is, how to escape this eveluation from happening before.

View 11 Replies View Related

Programming :: Redirecting Stdin / Stdout And Stderr For Program Run As Fork()/execl()?

Nov 24, 2010

I'm trying to write a program that will fork a series of FTP sessions. For each session, there should be separate input and output files associated with stdin and stdout/stderr.
I keep reading how I should be able to do that with dup2() in the child process before the execl(), but it's not working for me. Could someone please explain what I've done wrong? The program also has a 30-second sniper alarm for testing and killing of FTPs that go dormant for too long.

The code: (ftpmon.c)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


The output:

$ ftpmon
Connected to (
220 (vsFTPd 2.0.1)
ftp> waitpid(): Interrupted system call

Why am I getting the ftp> prompt? If the dup2() works, shouldn't it be taking input from my script and not my terminal? In stead, it does nothing, and winds up getting killed after 30 seconds. The log file is created, but it's empty after the run.

View 3 Replies View Related

General :: Why Would Executable Say It Doesn't Exist / When Try To Run It?

Sep 28, 2010

I have a compiled program, a tagger to identify parts of text, which claims it does not exist.This executable has to be called by a generated script, which is how I ran into this issue. What are the reasons this error could show up?The executable was copied from another machine.The file does have execution privileges (it gives a proper not-allowed message without them)I've tried copying the file to a different location (same problem)I've tried replacing the file with a fresh copy (same problem)The file does exist. Opening it with pico shows a file with binary data.

View 4 Replies View Related

Programming :: Shared Objects - Mapping And Linking?

Oct 28, 2010

I have a question about shared objects and when mapping and linking is established in the following code...Well more of a verification.

getsetx.c - shared object source code Code: unsigned long x = 0;

unsigned long getx(void)
return x;

Now its my understanding when I execute ./testit, will get mapped into its address space at start up and testit will link any functions as they are needed..

View 3 Replies View Related

Programming :: Pthread Mapping From Compiler To Kernel?

Aug 20, 2010

I'm trying to figure out how pthreads are mapped from the compiler to the Linux kernel. The pthread prototypes are found in a compiler header file (pthread.h), yet the kernel would be responsible for scheduling the threads. So, how does the compiler resolve the pthread symbols at compile time?

View 1 Replies View Related

Programming :: Mapping Browser Mouse-click To Character Beneath It?

Jun 29, 2011

How does one, in portable JavaScript, map a particular mouse-click, (x,y), to the character within the DOM element that is underneath it?

View 1 Replies View Related

General :: Executable File Apparently Doesn't Exist When Trying To Execute With Bash

May 9, 2011

I downloaded a program called tonespace which I extracted and then tried to execute the executable file with ./tonespace. This gives me the following message:

bash: ./tonespace: No such file or directory

When I use the command: file ./tonespace I get this: tonespace: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

I dont get it. The file is clearly there, yet when trying to execute it bash doesn't seem to recognize it.

It has permissions rwxr-xr-x and is not owned by root. Am I overlooking something?

View 2 Replies View Related

Programming :: Fork: Not Enough Memory While Executing "spawn Bash"

Apr 9, 2010

I have a TCL framewrok for my test cases automation. This is been working for last 1 year. But yesterday it exited with exception when a function was called. The exception was given as fork: not enough memory while executing "spawn bash"(procedure "runtrigger" line 36) invoked from within "runtrigger $fnAfter $sid_l $mapver" ("trigger" arm line 6) invoked from within

View 4 Replies View Related

Programming :: Creates A Child Process With Fork And, When The Child Ends, Receives The SIGCHLD Signal And Wait For Its Termination?

May 23, 2011

I have a doubt about signals in C programming. I have done this little program to explain it. It creates a child process with fork and, when the child ends, receives the SIGCHLD signal and wait for its termination.Ok, quite easy, BUT when I execute this code the SIGCHLD signal is received twice, first as an error (returns -1) and the second one to finish the child process.I don't understand the meaning of the first received signal. Why is it generated? Is the code wrong? (if you add the SIGINT and press Ctrl+C during the execution it also receives two signals instead of one)

Code: #include <stdio.h>
#include <unistd.h>
#include <string.h>


View 4 Replies View Related

Software :: Stdio.h - File Missing During GCC Compile

Mar 3, 2011

I have looked at the other threads and found nothing which pertains to my issue. I am using an older version of Debian 4.0 I cannot upgrade until I have a 2nd server running. I lost the 4.0 installation disks. During an apt-get install i did, I foolishly changed sources.list to other sources on the net which changed dependencies and removed needed packages, such as perlmagick, Crypt-SSLeay, aptitude, and possibly the glibc - ( my current glibc was changed to glic6). Since I have found my original 4.0 disk. restored the sources.list. ran an update. and restored many of the packages that were removed. (a big lesson to me I will never do that again)

Here is a simple program:
#include <stdio.h>
When I run a gcc or I use cc compile
I get this message: "stdio.h": No such file or directory found.
Yes I know I missing the file stdio.h. I have looked
in /usr/include /usr/lib nothing.

Apparently during my mistake the system installed the glibc6 and removed the "stdio.h" file and other dependencies. I would like to get back to where as was in terms of the glibc version I had. Aptitude currently shows the following packages that are available to me

DEB1:/etc# aptitude search glibc
v glibc-2.3.6-2 -
v glibc-2.3.6.ds1-1 -
p glibc-doc
- GNU C Library: Documentation
v glibc-pic
p libg++
GNU C++ extension library - runtime version
p libstdc++2.10-glibc2.2
- The GNU stdc++ library

The question is which one should I install, to get my "stdio.h" back again? Would I have to uninstall glibc6 first? Uninstalling glibc6 displays a big warning. Is there a way I can download just the "stdio.h" files?

View 5 Replies View Related

Programming :: Cpu Time Taken By An Executable To Run ?

Jun 2, 2010

I want to find the cpu time taken by an executable to run.. the executable is writting the output to a file. i want to write the time takem by cpu to the same output file.


abc is my executable which is taking input as input file and writing the result in output file.. i want to append cpu time information in the same file. can i do it with time command?

View 5 Replies View Related

Programming :: Keep The Bash-script Running If "exec Command" Fails

Aug 13, 2010

Is there a way to use exec, but if exec fails to go on with the script?


#!/usr/bin/env bash
exec startx
echo "Starting of X failed"

If startx fails, the echo will be seen on the screen. I tried all kind of stuff, but guess it ain't of much use to post it here. I searched the web, but searching for "exec and bash" in one sentence does give results which are not what i am looking for.

View 6 Replies View Related

General :: Cmem.c:38:19: Error: Stdio.h: No Such File Or Directory

Aug 10, 2010

I am trying to compile a memory map module cmem.ko from TI codec tools. This is for the DSPlink software development for the OMAP3530. I am compiling this on the host(Ubuntu). First error could not find cc1 and i re-installed gcc and added it to the path. That fixed that error but then I get to this:

cmem.c:38:19: error: stdio.h: No such file or directory
cmem.c:39:20: error: unistd.h: No such file or directory
cmem.c:40:22: error: sys/mman.h: No such file or directory


View 1 Replies View Related

Copyrights 2005-15, All rights reserved