Sponsored Content
Full Discussion: pipes and shells
Top Forums UNIX for Dummies Questions & Answers pipes and shells Post 302247309 by isato on Wednesday 15th of October 2008 11:15:03 AM
Old 10-15-2008
Whats wrong whit this pipe?

Could anyone tell me whats wrong whit this piping? the commands that they execute are correct. the command I am trying is ls|wc. Both processes go to the right if statement.


Code:
for(i=0;i<argc;i++){
   
       if(i==0&&argc>1){//first command
           if(pipe(pipa1)==-1)
               perror("pipe");
           if((pid=fork())<0)    
                perror("fork");
            if(pid==0){//child
                printf("jag är fösta kommandot");
                printf("I am a 1 process--%d, my parent is--%d jag skall exikvera--%s\n ",getpid(),getppid(),com[i].argv[0]);
                dupPipe(pipa1, WRITE_END, STDOUT_FILENO);
                execvp(com[i].argv[0],com[i].argv);
            }                
       }
       if (i>0 && argc==2) {       
         pid = fork();          
         if (pid == 0) {        
            printf("jag är andra kommandot");
            printf("I am a process--%d, my parent is--%d jag skall exikvera--%s \n ",getpid(),getppid(),com[i].argv[0]);
            dupPipe(pipa1, READ_END, STDIN_FILENO);
            execvp(com[i].argv[0],com[i].argv);
             }
   
        }


Code:
/* Duplicate a pipe to a standard I/O file descriptor, and close both pipe ends
 * Arguments:    pip    the pipe
 *        end    tells which end of the pipe shold be dup'ed; it can be
 *            one of READ_END or WRITE_END
 *        destfd    the standard I/O file descriptor to be replaced
 * Returns:    -1 on error, else destfd
 */
int dupPipe(int pip[2], int end, int destfd){
 
  if (-1 == dup2 (pip[end], destfd))
    {
      perror ("dupPipe()");
      return -1;
    }
  return destfd;
}

 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

2. Shell Programming and Scripting

cd using pipes

Hi, Can the cd command be invoked using pipes??? My actual question is slightly different. I am trying to run an executable from different folders and the path of these folders are obtained dynamically from the front end. Is there a way in which i can actually run the executable... (2 Replies)
Discussion started by: Sinbad
2 Replies

3. UNIX for Dummies Questions & Answers

Restricted Shells. . .

Hey, Could someone please help me distinguish between a captive account and a restricted shell? Many thanks, L. (0 Replies)
Discussion started by: crispy
0 Replies

4. UNIX for Advanced & Expert Users

Shells

I have came across the definitions of these shells korn bourne c etc .. but honestly till now i din't get the exact difference between these threes , the advantages ..... can anyone pinpoint me where it actually lies ..... don;t include me answers like aliasing in c is posible and not in bourne ..... (3 Replies)
Discussion started by: dino_leix
3 Replies

5. Linux

Version of Shells?

Can anyone tell me the version of shells for bash mc pdksh tcsh zsh For Red Hat Enterprise 4? Thank you very much! (2 Replies)
Discussion started by: Xplore
2 Replies

6. UNIX for Advanced & Expert Users

why we have different shells?

Can you pls. tell me, why we have different shells in UNIX OS ( Eg. SunOs) and also I would like to know what is the specific difference b/w SVR and BSD ? Thanks. (2 Replies)
Discussion started by: shahnazurs
2 Replies

7. Linux

/etc/shells on /etc/passwd

Hi All, Why does these list (below) doesn't belong to /etc/shells? sync:x:5:0:********************// :/sbin:/bin/sync shutdown:x:6:0:********************// :/sbin:/sbin/shutdown halt:x:7:0:********************// :/sbin:/sbin/halt webalizer:x:68:68:***************// ... (2 Replies)
Discussion started by: itik
2 Replies

8. Programming

Pipes in C

Hello all, I am trying to learn more about programming Unix pipes in C. I have created a pipe that does od -bc < myfile | head Now, I am trying to create od -bc < myfile | head | wc Here is my code, and I know I might be off, thats why I am here so I can get some clarification. #include... (1 Reply)
Discussion started by: petrca
1 Replies

9. UNIX for Dummies Questions & Answers

Shells

Lets say my default shell is bash and then i load up csh and then ksh. How would i exit csh without exiting ksh? so basically i gone from bash > csh > ksh and i wish to close csh (2 Replies)
Discussion started by: Bill Thompson
2 Replies

10. UNIX for Dummies Questions & Answers

Please what are shells?

I mean like this: http://shells.red-pill.eu/ Can anyone explain how this works? I hope my post is not spam. I think its related to linux. Thank you (1 Reply)
Discussion started by: postcd
1 Replies
CHSH(1)                                                            User Commands                                                           CHSH(1)

NAME
chsh - change login shell SYNOPSIS
chsh [options] [LOGIN] DESCRIPTION
The chsh command changes the user login shell. This determines the name of the user's initial login command. A normal user may only change the login shell for her own account; the superuser may change the login shell for any account. OPTIONS
The options which apply to the chsh command are: -h, --help Display help message and exit. -R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. -s, --shell SHELL The name of the user's new login shell. Setting this field to blank causes the system to select the default login shell. If the -s option is not selected, chsh operates in an interactive fashion, prompting the user with the current login shell. Enter the new value to change the shell, or leave the line blank to use the current one. The current shell is displayed between a pair of [ ] marks. NOTE
The only restriction placed on the login shell is that the command name must be listed in /etc/shells, unless the invoker is the superuser, and then any value may be added. An account with a restricted login shell may not change her login shell. For this reason, placing /bin/rsh in /etc/shells is discouraged since accidentally changing to a restricted shell would prevent the user from ever changing her login shell back to its original value. FILES
/etc/passwd User account information. /etc/shells List of valid login shells. /etc/login.defs Shadow password suite configuration. SEE ALSO
chfn(1), login.defs(5), passwd(5). shadow-utils 4.5 01/25/2018 CHSH(1)
All times are GMT -4. The time now is 09:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy