Sponsored Content
Full Discussion: Parent,child wait,signal
Top Forums Programming Parent,child wait,signal Post 302528440 by Cuervo on Tuesday 7th of June 2011 06:14:41 AM
Old 06-07-2011
Ok i ll send you everything in case you understand what is hhappening. I do everything as i saw it online.I keep getting an Input/Output error on read.

Code:
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <sys/wait.h>
#include  <stdio.h>
#include  <signal.h>
#include  <sys/ipc.h>
#include  <sys/shm.h>
#define MAX_BUF 5000

int main(int argc, char **argv)
{
    pid_t pid;
    int i,fd;
    char buf[MAX_BUF]="",data[MAX_BUF]="";
    char * myfifo = "/cygdrive/c/a/progsys/tmp";
     if (mkfifo(myfifo, 0666) != 0)
        perror("mkfifo() error");
    for(i=1;i<5;i++)
    {
        strcat(data,argv[i]);
        strcat(data," ");    
    }
    fprintf(stderr,"#%s#",data);
    pid = fork();
    if (pid == -1) 
    { 
        perror("Can't create child\n");
        exit(1);
    }
    else 
        if (pid == 0) 
        {
   
            if(execl("b.exe","b.exe",NULL) == -1)
                fprintf(stderr,"execl Error!\n");
        }
        else 
            {
                if(fd = open(myfifo, O_WRONLY)<0)  perror("open() error for read end");
                   if (write(fd, data, strlen(buf))<0);    perror("write() error");
                printf("Parent ended ");
                close(fd);
                fd = open(myfifo, O_RDONLY);
            }
}

Child
Code:
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <sys/wait.h>
#include  <stdio.h>
#include  <signal.h>
#include  <sys/ipc.h>
#include  <sys/shm.h>
#define MAX_BUF 5000

int main(int argc, char **argv)
{
    int fd,i,j,iteration=1,lowerBound,upperBound,numPoints,numread;
    char * myfifo = "/cygdrive/c/a/progsys/tmp";
    char buf[MAX_BUF]="",permbuf[MAX_BUF]="",sourcefile[MAX_BUF]="",finalsourcefile[MAX_BUF]="";
    if (fd = open(myfifo, O_RDONLY)<0) perror("open() error for read end");
    sleep(5);
    if (numread=read(fd, buf, sizeof(MAX_BUF))<0) perror("read ferror for read end");
    buf[numread]='0';
    write (1,buf,numread);

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how to make a parent wait on a child shells running in background?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (1 Reply)
Discussion started by: albertashish
1 Replies

2. Programming

How can I make the parent thread wait

Hi All, I will be glad if you could help me resolve this problem. I have created two detachable threads and wanted to them execute independent of the parent thread ( the main task which creates the detachable threads). But I see no output coming from the execution of two detachable threads.... (4 Replies)
Discussion started by: jayfriend
4 Replies

3. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

4. UNIX for Dummies Questions & Answers

Sending signal from child to parent process!

Hi All, I facing a problem in handling signals between parent process communication. I am trying to send a signal(SIGINT) from child to parent. I am using kill function to do so and I am trying to read the signal using sigaction(). But the program is ending abruptly and I am not able to figure out... (4 Replies)
Discussion started by: vkn_1985
4 Replies

5. Programming

Parent process starts before the child using signal, in C

Hi, i want that the parent process start before the child, this code doesn't work, if the child start before the parent it wait for signal, then the father send the signal SIGALRM and the child catch it and call printf; else the father call printf and send the signal to the child that call its... (1 Reply)
Discussion started by: blob84
1 Replies

6. Homework & Coursework Questions

Need help with deleting childīs parent and child subprocess

1. The problem statement, all variables and given/known data: I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process. 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: WhiteFace
0 Replies

7. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

8. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

9. Shell Programming and Scripting

parent process needs to wait

I have two scripts lets say A.expect and B.sh needs to be executed. I am executing B.sh from A.expect where B.sh has sleep command. My problem is that when B.sh encounters the sleep command my A.expect starts executing and exits. but my A.expect should execute only after completing B.sh. Is... (3 Replies)
Discussion started by: priya@2012
3 Replies

10. Shell Programming and Scripting

How make parent to wait from child process?

Hi all, I am starting mgen5 for sometime depends on input from a file, in a child process. now I want to make parent to wait in this child process till mgen5 finishes, or timeout happens. could anyone please tell me how to make parent to wait in child process in shell script? thanks... (2 Replies)
Discussion started by: girijajoshi
2 Replies
GETPROTOENT_R(3)					     Linux Programmer's Manual						  GETPROTOENT_R(3)

NAME
getprotoent_r, getprotobyname_r, getprotobynumber_r - get protocol entry (reentrant) SYNOPSIS
#include <netdb.h> int getprotoent_r(struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result); int getprotobyname_r(const char *name, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result); int getprotobynumber_r(int proto, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): getprotoent_r(), getprotobyname_r(), getprotobynumber_r(): _BSD_SOURCE || _SVID_SOURCE DESCRIPTION
The getprotoent_r(), getprotobyname_r(), and getprotobynumber_r() functions are the reentrant equivalents of, respectively, getprotoent(3), getprotobyname(3), and getprotobynumber(3). They differ in the way that the protoent structure is returned, and in the function calling signature and return value. This manual page describes just the differences from the nonreentrant functions. Instead of returning a pointer to a statically allocated protoent structure as the function result, these functions copy the structure into the location pointed to by result_buf. The buf array is used to store the string fields pointed to by the returned protoent structure. (The nonreentrant functions allocate these strings in static storage.) The size of this array is specified in buflen. If buf is too small, the call fails with the error ERANGE, and the caller must try again with a larger buffer. (A buffer of length 1024 bytes should be sufficient for most applications.) If the function call successfully obtains a protocol record, then *result is set pointing to result_buf; otherwise, *result is set to NULL. RETURN VALUE
On success, these functions return 0. On error, they return one of the positive error numbers listed in ERRORS. On error, record not found (getprotobyname_r(), getprotobynumber_r()), or end of input (getprotoent_r()) result is set to NULL. ERRORS
ENOENT (getprotoent_r()) No more records in database. ERANGE buf is too small. Try again with a larger buffer (and increased buflen). CONFORMING TO
These functions are GNU extensions. Functions with similar names exist on some other systems, though typically with different calling sig- natures. EXAMPLE
The program below uses getprotobyname_r() to retrieve the protocol record for the protocol named in its first command-line argument. If a second (integer) command-line argument is supplied, it is used as the initial value for buflen; if getprotobyname_r() fails with the error ERANGE, the program retries with larger buffer sizes. The following shell session shows a couple of sample runs: $ ./a.out tcp 1 ERANGE! Retrying with larger buffer getprotobyname_r() returned: 0 (success) (buflen=78) p_name=tcp; p_proto=6; aliases=TCP $ ./a.out xxx 1 ERANGE! Retrying with larger buffer getprotobyname_r() returned: 0 (success) (buflen=100) Call failed/record not found Program source #define _GNU_SOURCE #include <ctype.h> #include <netdb.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> #define MAX_BUF 10000 int main(int argc, char *argv[]) { int buflen, erange_cnt, s; struct protoent result_buf; struct protoent *result; char buf[MAX_BUF]; char **p; if (argc < 2) { printf("Usage: %s proto-name [buflen] ", argv[0]); exit(EXIT_FAILURE); } buflen = 1024; if (argc > 2) buflen = atoi(argv[2]); if (buflen > MAX_BUF) { printf("Exceeded buffer limit (%d) ", MAX_BUF); exit(EXIT_FAILURE); } erange_cnt = 0; do { s = getprotobyname_r(argv[1], &result_buf, buf, buflen, &result); if (s == ERANGE) { if (erange_cnt == 0) printf("ERANGE! Retrying with larger buffer "); erange_cnt++; /* Increment a byte at a time so we can see exactly what size buffer was required */ buflen++; if (buflen > MAX_BUF) { printf("Exceeded buffer limit (%d) ", MAX_BUF); exit(EXIT_FAILURE); } } } while (s == ERANGE); printf("getprotobyname_r() returned: %s (buflen=%d) ", (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" : strerror(s), buflen); if (s != 0 || result == NULL) { printf("Call failed/record not found "); exit(EXIT_FAILURE); } printf("p_name=%s; p_proto=%d; aliases=", result_buf.p_name, result_buf.p_proto); for (p = result_buf.p_aliases; *p != NULL; p++) printf("%s ", *p); printf(" "); exit(EXIT_SUCCESS); } SEE ALSO
getprotoent(3), protocols(5) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2010-09-10 GETPROTOENT_R(3)
All times are GMT -4. The time now is 06:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy