Sponsored Content
Full Discussion: Help with Mkfifo and exec
Homework and Emergencies Homework & Coursework Questions Help with Mkfifo and exec Post 302469573 by dano88 on Sunday 7th of November 2010 03:28:18 AM
Old 11-07-2010
Help with Mkfifo and exec

Hello guys!

I am doing a project for the university and I have to do that a process has to create several children through fork(). The father process sends a pathname to each one through exec and the children must send to the father a list with the files from each directory.

The father is waiting and the children don't send anything. I must to do the pipe with mkfifo. I am trying to send text from the children but nothing happens. This is the code that I have wroten:



Code:
struct stat buf;
 mkfifo(NOMBREFIFO, S_IRWXU);
    while (--argc>0){
        stat (argv[argc], &buf);
        if (S_ISDIR(buf.st_mode)){
            pid = fork();
            
            if (pid<0) fprintf (stderr, "error %d", errno); 
            if (pid==0) printf ("hhhhhhhhh");
            if (pid==0 && (exec=execl ("./listarordenado", argv[argc], NULL))<0) fprintf (stderr, "error %d", errno);
            if (pid>0 && wait(&status) && waitpid (pid, &status, 0)){
                printf ("ssssssssss");
                 while(TRUE) {
                      fp=open(NOMBREFIFO,O_RDONLY);
                      nbytes=read(fp,buffer,TAM_BUF-1);
                      buffer[nbytes]='\0';
                      printf("%d Cadena recibida: %s \n",i, buffer);
                      close(fp);
                      i++;
                }
                 }
         }
      } 


/////***code of listarordenado*//


for (i=0; i<50; i++){
        if ((fp=open(NOMBREFIFO,O_WRONLY))==-1)
            perror("fopen");
          else {    
                descr=write(fp,argv[1],strlen(argv[1]));
        }
         
      close(fp);
    }

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University: Universidad de Castilla-La Mancha (Ciudad Real, spain)
Professor: Carlos Gonzalez Morcillo :: Personal Web Page www. inf-cr.uclm.es/www/cglez/
Degree: "Computer engineering"
Subject: "Ampliación de Sistemas Operativos" + info: www. esi.uclm.es:8081/www/GuiaDocente/GuiaDocente0910/guias/42534_0910.pdf
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

exec

In exec function say when i would like to remove the files exec rm{}\; Why is this "\" needed immediately after {} and what if i dont give it? TIA, Nisha (1 Reply)
Discussion started by: Nisha
1 Replies

2. UNIX for Dummies Questions & Answers

Struggling with mkfifo

Gurus, I did my research (on google, this site and my local library) but I am *still* lost. I am trying to teach myself about `named pipes` playing around with MKFIFO (Why not?). (1) It seems MKNOD is reserved to ROOT whereas MKFIFO is accessible to all users. Am I correct? If the answer is... (20 Replies)
Discussion started by: alan
20 Replies

3. UNIX for Advanced & Expert Users

exec

I have read that exec "replaces the current process with a new one". So I did $ exec ls and after this executed, my shell disappeared. I am assuming that my shell had PID xyz, and when I did exec ls, this ls got pid xyz, and when it terminated, there was no more shell process running, and... (5 Replies)
Discussion started by: JamesByars
5 Replies

4. Shell Programming and Scripting

exec command

can any one pls explain the meaning of exec 1<&5 ?? its urgent (2 Replies)
Discussion started by: santosh1234
2 Replies

5. Shell Programming and Scripting

Help with use of `` vs exec

Hi all, I had an issue regarding use of `` or exec in perl . `` are considered to be unsafe. Why? In my case an user would be giving some parameters as input and I will form an command of it and execute it using ``. It is important to capture output as i have to parse the output. As well as I need... (0 Replies)
Discussion started by: bharadiaam
0 Replies

6. Programming

Help with Mkfifo and exec

Hello guys! I am doing a project for the university and I have to do that a process has to create several children through fork(). The father process sends a pathname to each one through exec and the children must send to the father a list with the files from each directory. The father is... (1 Reply)
Discussion started by: dano88
1 Replies

7. UNIX for Advanced & Expert Users

-exec cp

Hi, on AIX 6.L I want to copy the result of grep -v to test directory then : `hostname`@oracle$ls -l | grep -v RINT -exec cp {} test grep: can't open -exec grep: can't open cp grep: can't open {} test:°`. Can you help me ? Thank you. (3 Replies)
Discussion started by: big123456
3 Replies

8. UNIX for Dummies Questions & Answers

exec

Hi, i don't understand this part of one script exec >> $Log_File 2>&1 (1 Reply)
Discussion started by: messi777
1 Replies

9. UNIX for Advanced & Expert Users

Using -exec with and without -name

Hi, I need to delete the last N days file using find. I am trying to use find . -mtime -10 -print which lists down required files. but when i use find . -mtime -10 -exec ls -lrt {} \; it gives me all files in the directory including the required files but the required files... (7 Replies)
Discussion started by: v_m1986
7 Replies

10. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies
getexecname(3C) 					   Standard C Library Functions 					   getexecname(3C)

NAME
getexecname - return pathname of executable SYNOPSIS
#include <stdlib.h> const char *getexecname(void); DESCRIPTION
The getexecname() function returns the pathname (the first argument of one of the exec family of functions; see exec(2)) of the executable that started the process. Normally this is an absolute pathname, as the majority of commands are executed by the shells that append the command name to the user's PATH components. If this is not an absolute path, the output of getcwd(3C) can be prepended to it to create an absolute path, unless the process or one of its ancestors has changed its root directory or current working directory since the last successful call to one of the exec family of functions. RETURN VALUES
If successful, getexecname() returns a pointer to the executables pathname; otherwise, it returns 0. USAGE
The getexecname() function obtains the executable pathname from the AT_SUN_EXECNAME aux vector. These vectors are made available to dynam- ically linked processes only. A successful call to one of the exec family of functions will always have AT_SUN_EXECNAME in the aux vector. The associated pathname is guaranteed to be less than or equal to PATH_MAX, not counting the trailing null byte that is always present. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
exec(2), getcwd(3C), attributes(5) SunOS 5.10 17 Dec 1997 getexecname(3C)
All times are GMT -4. The time now is 08:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy