Programming :: Select() Call Does Not Detect Data In Pipe Between Parent And Child Program

Sep 23, 2009

i wanted to capture the stdout and stdin of a child process within a parent so that any output of child is sent to the parent and any input taken from the parent. code is simple enough and i have followed all code guidlines on the internet (some guidlines do differ also) my select call either hangs if i do not give a tmeout and with a timeout it returns 0 descriptors to be written to or read from:

below is the simple code for parent:

int main(void)
{
int outfd[2];
int infd[2];

[code].....

why select hangs without a timeout ... why can it not detect that the pipe is write ready i.e parent can write to it ... if it does not detect tha read pipe as having data...

View 5 Replies


ADVERTISEMENT

Programming :: Ipc Between Parent And Child Processes Using Pipe?

Oct 13, 2010

If a process forks its child and communicate with the child using pipe, do closing the write end of the pipe and terminating the writing process have the same effect?

View 3 Replies View Related

Programming :: Detect Pipe From Running C Program?

Jan 24, 2009

I'm looking for a way to detect whether or not a program has been called from pipe, e.g.

Code:

whatever | my_program
versus simply just being exectuated directly:

Code:

my_program

Why? In the first case, I want to run the program non-interactively, and in the latter case I want to print out user-friendly messages. I've been thinking along the lines of some check I haven't yet found, like:

Code:

if( stream_buffer_is_not_empty() )
print_interactive_messages();

View 1 Replies View Related

Programming :: Get Child Pids From Parent Pid In Kernel Mode?

Jun 28, 2010

i need C code to get child pids from its parent pid in linux and in kernel mode, is there anything like getpid() or getppid() which works in kernel mode?

View 2 Replies View Related

Programming :: Perl Script (Both Parent And Child) Dieing

Apr 13, 2010

I am writing a perl script where forking a child and the child is waiting for some response from C++ exe. Here is the code snippet:

Code:
my $retPid = fork;
if ($retPid) {
# I am parent ...
# Install signal handler
$SIG{CHLD} = &REAPER; ...
# sleep for a week (6 hours at a time)
for ($cnt = 0; $cnt < 28 ; $cnt++) {
select(undef, undef, undef, 21600);
last if ( ! -e "/proc/$retPid" ); } ...
} else {
# I am child
($iid, $rc, %data) = $cpp_exe->getResponse(604800); # 1 week timeout ... }

If the cpp_exe takes very long time (around 30 hours) to respond then the perl script (both parent and child) is dieing. The SIG{CHLD} handler defined in parent is not getting called. It seems parent is dieing first then child is dieing (or may be both dieing at the same time). Why the script is dieing?

View 1 Replies View Related

Programming :: Parent Process Block - Status Of Child

Mar 22, 2011

I am going to create a parent process and fork a child process from it. I want to write a code in such a way that whenever my child process end it must indicate that the child process is terminated by a signal or not. This code must be written in the parent process block.

View 6 Replies View Related

Programming :: Why Does A Child Exit When The Parent Receives A Signal

Mar 16, 2011

I have a problem with the last point of some homework I have for an OS class. I need the program to print the pid upon execution, then for 10 seconds react to SIGUSR1, SIGUSR2 and SIGTERM. If either USR1 or USR2 is received, the 10 seconds are reset. Some of the functions I'm told to use are alarm(), pause() and signal(). The nicest way I found was to handle SIGUSR1, SIGUSR2 and SIGALRM in the parent process, with SIGALRM killing the child (with a SIGTERM). In the child a pause() (or for(; pause() would be enough for it to be alive until killed from the SIGALRM handler in the parent.

What I found is that I can't just do a wait() in the parent process, waiting for the child to be killed, since whenever the parent receives a SIGUSR1 or SIGUSR2, the right handler is called but the child exits nicely. I tried blocking/ignoring those signals in the child, since the default behaviour for SIGUSR1 and SIGUSR2 is to terminate the process, but the result is the same. The only way I could do it is using a waitpid() within a do { } while(!WIFSIGNALED(status)) since when the child gets killed with the parent's kill(), it's WIFSIGNALED, whereas when it exits after the parent handles a SIGUSR1/2, it's WIFEXITED.

P.S. What I'm doing to achieve the expected 10s window is calling alarm(10) in the parent process and again within the SIGUSR1/2 handlers. In the SIGALRM handler I kill the child and within the child I simply do a for(; pause()

View 4 Replies View Related

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

Feb 24, 2010

Code:

int main()
{
int pi;
int i=10;
pid=fork();

[code]....

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.

Code:

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

[code]....

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 :: Splitting A Parent Process Into 2 Child And Then Merging Result?

Sep 15, 2010

What i am trying to do is i want to add numbers from 1 to 100. but that too using multiprocessing. So i made a c programme and using fork() command made two child processes. Now in one child process i am adding from 1 to 50. and in another i am adding 51 to 100. and then in the parent process adding the two results to get the final one. Now the result from the two function i am getting correctly. But after the wait() call the value returned is lost : See the programme below for reference

# include<stdio.h>
# include<unistd.h>
# include<sys/wait.h>
# include<stdlib.h>

[code].....

View 6 Replies View Related

Programming :: Clarification In The Select System Call?

Dec 8, 2010

I have a process that forks, where the childs puts some data of random size and exits while the parent should get the data and does some manipulation.. here I have used a pipe for child to write the data and parent to read the data.. Child simply dumps the data, and the data is of any size even child and parent doesnt know.
I have used select in the parent to see whether there is any data coming on the reading end of the pipe.. if there is a data.. I copy into a buffer.. Im reading the data continusly when the child exits after closing the writing end of pipe. Parent gets blocked on the read part But my question is how parent know the other of pipe is closed when using the select call. In otherwords.. while using select in readfds, how would i know the other end has closed the pipe..

View 2 Replies View Related

Programming :: Getting The Name Of The Process That Sent Data To A Pipe?

Feb 16, 2011

I am trying to automate some directory naming when we're manually running some scripts and are using tee to direct the output to a file (log). Right now this is what we do

Code:

./some_script.sh 2>&1 | tee /home/user/some_dir/logs/manual/some_script_20110216_1628.log

As a matter of laziness and keeping the log files consistently named, I'd like to create a function to pipe it to so that it's doing all the naming How I envision the command running

Code:

./some_script.sh 2>&1 | myfunc

And what the logfile name should look like (and in the right directory)

Code:

some_script_20110216-1628.log

I was thinking of adding a function to our profile to handle this. Just in testing I was trying to stream line right on the command line, but I'm having some difficulty in getting the name of the script that is pushing data over the pipe. Here is what I've tried

Code:

./some_script.sh 2>&1 | tee $(cd ../logs/manual; pwd)/$0_$(date +%Y%m%d)-$(date +%H%M).log

but that created a file named

"bash_20110216-1628.log"

View 3 Replies View Related

Programming :: Read Unknown Data Length From Usb Pipe?

Aug 12, 2010

I've written a usb device driver and a program that sends and receives data over the bulk pipe. The read function sometimes returnsI'm reading an unknown amount of data. However, using a usb tracker I can see that the correct data is being sent.The error only occurs sometimes.I expect that the read function is told to read more data that it receives it would fail and return -1, however if this was the case then every read call would fail.

View 4 Replies View Related

Programming :: Ioctl TIOCMGET Call Doesn't Detect TIOCM_CTS

Apr 6, 2011

I am having the following problem. The following code works fine on my P.C. Ubuntu x64, and on a jetway mini-itx board with an atom processor. The problem is, the same code doesn't work on the intel equivalent of the jetway board. I thought the maybe, I didn't have the port configured right, so I turned on Hardware Flow control and also tried turning on the modem bits I needed with TIOCMBIS. Neither worked. Here is the code. There are two threads, one of them, respsponding to the client, and using the RTS and DTR pins to power two relays. The other, manages listening to CTS and DSR for input. Here is the class with the first thread.

Code:

/*
* DigitalIOCore.cpp
*
* Created on: Nov 1, 2010
* Author: jonathan

[code]....

View 9 Replies View Related

General :: Child Process That Dies And Has No Parent?

Dec 17, 2010

What happens to a child process that dies and has no parent process to wait for it and what's bad about this?

View 2 Replies View Related

General :: Killing Parent Process Without Killing Child Process (Linux C Programming)?

Mar 10, 2011

I want to kill parent process after "fork()" method. but if I kill parent process with "exit(0)" method, main() thread is terminated as well so child prosess doesn't work anymore. Is there any way to kill only parent process without affecting to child process?

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

[code]....

View 1 Replies View Related

SUSE :: Kill Child Process Without Killing The Parent?

Jun 21, 2010

I am trying to kill child process without killing the parent and seem to be having issues doing so. I have tried quite a few different commands and the end result is either killing all of them including the parent or not killing them at all.

View 1 Replies View Related

General :: Cannot Inherit The Permission From Parent Folder To Child

Apr 26, 2011

I have setgid permission on my home directory (/home/XXXX) the permission look like below.

Code:

drwxrws--- 2 toshi jadu 4096 Apr 26 16:54 getset

If I create new directory in this getset folder the permission of getset folder could not inherit.

Code:

#cd getset
#mkdir test2
#ls |grep test2
drwxr-s--- 2 toshi jadu 4096 Apr 26 16:56 test2

As I know the setgid utility allow to inherit the permission from parent directory to child directory.

View 4 Replies View Related

General :: Command To Find Parent And Child Process?

Apr 21, 2011

I have a script that calls other scripts/commands which may or may not spawn other process. From my understanding, when I do a ps -ef, the highest numbered process ID is supposed to be the parent ID of all the other related child processes, is this correct? In most or all circumstances, I do a ps -ef | grep <processid> of my script and anything that spawns off that process IDs I assumed are the child processes of my script. If I want to terminate my script and all other child processes, then I kill the parent ID which is the highest numbered PID and this will subsequently kill all other child process IDs, is this correct?

Now, my question is whether there is any quick way of showing what are the child processes of a parent ID instead of what am currently doing now which is visually checking which one is the parent ID and "assuming" that the highest numbered PID is the parent ID of all the other processes. Below is a sample output of running ps -ef | grep exp | grep -v grep. I assume from the output below that the parent process/ID is PID 11322, is that correct?

Code:

oracle 11154 11153 0 21:20 ? 00:00:00 /bin/sh -c (. ~oracle/.profile; /bin/ksh /usr/local/oracle/scripts/expdp_o
oracle 11155 11154 0 21:20 ? 00:00:00 /bin/sh -c (. ~oracle/.profile; /bin/ksh /usr/local/oracle/scripts/expdp_o
oracle 11190 11155 0 21:20 ? 00:00:00 /bin/ksh /usr/local/oracle/scripts/expdp_schema.ksh dev01
oracle 11322 11190 0 21:20 ? 00:00:00 expdp

View 2 Replies View Related

Software :: Nested Shell - Disown Job Not Found (Parent Or Child)

Jun 1, 2011

I'm in a nested shell trying to use disown to re-root myself as well as a child. Looks like this:

Code:
# echo $$
1234
# disown 1234
disown: job not found: 1234
# disown $$
disown: job not found: 1234
# pgrep mychild
2222
# disown 2222
disown: job not found: 2222

This is in zsh. The goal is to have process 1 (the root of all processes) to become the parent.

View 3 Replies View Related

General :: Child Processes Of A Parent Process Occupying Socket Memory?

Jul 22, 2010

I am facing an issue where the process starts hanging. When I closely look at the logs I come to know that some of the child processes that are forked by the parent process are not finished.

1) Is it possible that the child processes that are not finished occupy the socket memory of the parent process and ultimately a point is reached where no socket memory is available to fork new child processes.

2) What is the standard limit of socket memory in linux?

3) What is the fate of such child processes (as I have mentioned above)?

4) How to debug such cases so that the exact problematic area is identified?

View 2 Replies View Related

General :: Find All Child Processes Of A Parent Process Given To Script As Argument?

Feb 15, 2011

well i have just started with shell scripting...how to find all child processes of a parent process given to script as argument.

View 10 Replies View Related

Server :: Squid Parent: Child Process XXXXX Exited With Status 1?

May 24, 2010

I have a transparent proxy Squid-3.0 on Slackware 12.2. I used cron to restart squid every day at 7:30 AM (just /path.to.squid/squid -k kill && /path.to.squid/squid) Some days ago I saw in /var/log/messages that Squid was killed but haven't started. I started it manually and everything was OK. But today everything repeated. And the log file is interesting. I tried to find about it on http://squid-cache.org/ but al in vain. This is from /var/log/messages :

Code:

May 24 07:30:02 konura squid[17188]: Squid Parent: child process 17199 exited due to signal 9
May 24 07:30:02 konura squid[19038]: Squid Parent: child process 19040 started
May 24 07:30:03 konura squid[19038]: Squid Parent: child process 19040 exited with status 1
May 24 07:30:06 konura squid[19038]: Squid Parent: child process 19045 started

[code]....

I need to say that I haven't edited the config file for a long time, but this problem started to happen. ADDED, Solved: I'm not sure, but maybe I found the decision. I deleted about 400 mb of Sarg logs from /var partition. And now squid runs well. Besides, before deleting old logs, 'crontab -e' and 'pkgtool' didn't work And the system wrote me that it's no space left on device. At the same time, 'df -h' showed me that all partitions had enough free space. Seems strange, but that's it. After deleting old proxy statistics, generated by Sarg (this is about 400 mb) 1)squid runs OK and 2)there are no more that annoying messages about abscence of free space.

View 1 Replies View Related

Programming :: Sendto Function Call In UDP Client Program ?

Jan 5, 2010

The following is the UDP client code I am using.

Code:

Even the server is down, sendto function is not returning -1.

Instead, it is returning the length of the message as if it is success.

View 1 Replies View Related

Programming :: Handle A Broken Pipe Exception (SIGPIPE) In FIFO Pipe?

Mar 2, 2011

I've written a simple server in linux used fork to create a FIFO pipe.The server create two FIFO pipe.One for server read data from client and write data to client.Then another pipe for client read data from server and write data to server.When the server read data from a client used server-pipe and then write data to client.But ,if the client no read open the pipe,the server side write will be crashed because of a broken-pipe SIGPIPE. How to check whether the read side is opened?Or,how to catch the SIGPIPE,and then my server will still execute on,not crashed!!

View 5 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>

[code]....

View 4 Replies View Related

Software :: Script That Call A Java Program That Call A System Command?

Nov 29, 2010

In practice I have a script that call a java program that call a linux system command. The script if I run it, from a shell functions well,so it is not a java problem. The problem come out when i put this script in a crontab schedulation. The result in this case is that java do not execute the system command. I think it depends on crontab

View 4 Replies View Related

Programming :: Python - Call Function From The Command Line After Compile The Program?

Dec 28, 2010

If i have a python file with a function call_me(a,b),how can I call this function from the command line ,after i compile the program?

View 5 Replies View Related

Programming :: How To Detect Compressible Data

Apr 13, 2011

I am working on a project that takes multiple blocks of memory that are no more than 1500 bytes in side and tries to compress them. Currently I just compress them and compare the old length to the new length. If the new length is smaller it copies the compressed data into the original datas memory space.The problem I have is when lots of these blocks of memory do not compress well its huge amounts of wasted CPU.

View 6 Replies View Related

General :: Child Process Can't Print Strings After Call Signal_handler?

Nov 2, 2010

I'm studying about signal in Linux Kernel and I got a problem about signal handler and output buffer.

I just want to know about stdout buffer related parent process and child process.

The problem is - parent process received SIGINT signal_handler that I implement is called. And after signal_handler is called, it print string "pid : xxx state : RUNNING" ... but after end of signal_handler function, child process might be print string but it isn't print at all.

I'm not asking right code, but I want to know why is this happened and concepts about signal handler, buffer - between parent process and child process.

here is a code signal_handler:

Quote:

void TC3_handler()
{
pid_t pid;
ProcState ps;
pid = GetProcessId();

[Code]....

chlid process counts number in infinite loop, but after call signal_handler, it can't print at all.. just waiting for SIGINT..

View 2 Replies View Related

Programming :: Detect Opening Of A File Using A C Program?

Jul 19, 2011

how to detect if a file is being opened by any application so that i can block it just before opening it... Actually i am working on android and using iNotify in JNI to detect the OPENING of a file...but the file is getting opened before the iNotify detects it..and therefore its displaying the contents of the file unmodified .. The actual requirement is that if anyone is trying to open the file it should be modified by my program and then the modified file should be opened.

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved