LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-25-2010, 03:28 AM   #1
chakki
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Rep: Reputation: 0
Unhappy IPC using PIPE _C program


Please help me,,,,,

subject:inter process communication using pipe

please give me a program in c to send N numbers from a parent process to child process and display them.

please please its urgent..
actually i am beginner in this IPC topic.

so please give me a consideration.
if possible give me the tutorial also.
 
Old 11-25-2010, 04:01 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by chakki View Post
please give me a program in c to send N numbers from a parent process to child process and display them.
Search Gooooogle with the following keywords:
Quote:
Linux Named Pipes examples
 
Old 12-07-2010, 12:35 AM   #3
chakki
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Angry

[QUOTE=anishakaul;4170523]Search Gooooogle with the following keywords:[/Q
not able to find out the required materials from that....
 
0 members found this post helpful.
Old 12-07-2010, 01:11 AM   #4
poojithas
LQ Newbie
 
Registered: Jun 2010
Location: Chennai, India
Distribution: Ubuntu 10.04
Posts: 22

Rep: Reputation: 0
IPC using PIPE _C program

fd_server.c
Code:
/*
Compile: gcc -o fd_server fd_server.c
*/
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#define NP1        "/tmp/np1"
#define NP2        "/tmp/np2"
#define MAX_BUF_SIZE    255

int main(int argc, char *argv[])
{
    int rdfd, wrfd, ret_val, count, numread;
    char buf[MAX_BUF_SIZE];

    /* Create the first named - pipe */
    remove(NP1);
    ret_val = mkfifo(NP1, 0666);
    if (ret_val == -1) {
        perror("Error mkfifo(NP1)");
        return 1;
    }
    else
       printf("pipe %s created\n",NP1);

    /* Create the second named - pipe */
    remove(NP2);
    ret_val = mkfifo(NP2, 0666);
    if (ret_val == -1) {
        perror("Error mkfifo(NP2)");
        return 1;
    }
    else
       printf("pipe %s created\n",NP2);

    /* Open the first named pipe for reading */
    if ((rdfd = open(NP1, O_RDONLY)) == -1) {
        perror("Error open(NP1)");
        return 1;
    }
    else
       printf("NP1 opened in read mode FD-%d\n",rdfd);

    /* Open the second named pipe for writing */
    if ((wrfd = open(NP2, O_WRONLY)) == -1) {
        perror("Error open(NP2)");
        return 1;
    }
    else
       printf("NP2 opened in write mode FD-%d\n",wrfd);

    /* Read from the first pipe */
    numread = read(rdfd, buf, MAX_BUF_SIZE);

    buf[numread] = '\0';

    printf("Full Duplex Server : Read From the pipe : %s\n", buf);

    /* Convert to the string to upper case */
    count = 0;
    while (count < numread) {
        buf[count] = toupper(buf[count]);
        count++;
    }

    /* 
     * Write the converted string back to the second 
     * pipe 
     */    
    write(wrfd, buf, strlen(buf));
}
fd_client.c
Code:
/*
Compile: gcc -o fd_client fd_client.c
*/

#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#define NP1		"/tmp/np1"
#define NP2		"/tmp/np2"
#define MAX_BUF_SIZE	255

int main(int argc, char *argv[])
{
    int wrfd, rdfd, numread;
    char rdbuf[MAX_BUF_SIZE];

    /* Check if an argument was specified. */

    if (argc != 2) {
        printf("Usage : %s <string to be sent to the server>\n", argv[0]);
        return 1;
    }

    /* Open the first named pipe for writing */
    if ((wrfd = open(NP1, O_WRONLY)) == -1) {
        perror("Error open(NP1)");
        return 1;
    }
    else
       printf("NP1 opened in write mode FD-%d\n",wrfd);

    /* Open the second named pipe for reading */
    if ((rdfd = open(NP2, O_RDONLY)) == -1) {
        perror("Error open(NP2)");
        return 1;
    }
    else
       printf("NP2 opened in read mode FD-%d\n",rdfd);

    /* Write to the pipe */
    write(wrfd, argv[1], strlen(argv[1]));

    /* Read from the pipe */
    numread = read(rdfd, rdbuf, MAX_BUF_SIZE);

    rdbuf[numread] = '\0';

    printf("Full Duplex Client : Read From the Pipe : %s\n", rdbuf);
}
 
Old 12-07-2010, 04:17 AM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by chakki View Post
not able to find out the required materials from that....
Ohh and what were you expecting from Google ... "to give you a program in c to send N ... and your homework for you" ???

I asked you to search for the "named pipes" expecting you to understand how they work, try a few programs on your own and post back the problems you faced!!
 
Old 12-08-2010, 01:56 AM   #6
chakki
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Original Poster
Rep: Reputation: 0
...THANKS ANISHA......!!!
actuallllly, i was asked to do such a program by subject in charge.
and I am totally unaware about these pipes,message queue ,semaphore and all in the program side.(I mean, the implementation side...),...nyway thank you...
 
Old 12-08-2010, 01:59 AM   #7
chakki
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Original Poster
Rep: Reputation: 0
there is another question....

Teacher X sends two filenames to student Y who has to find out the file(s) which has
1.read permission
2.write permission
Implement using pipes.X and Y are processes.


...and, still I don't know how to solve this .....

if u have any materials to help such a beginning stage student please forward....
 
Old 12-08-2010, 02:38 AM   #8
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
chakki

Perhaps you didn't understand what I was saying, here on this forum no one is going to write or give the whole code to you. No I am not being rude, but the volunteers of this forum can only guide and nudge you in the right direction for which you are supposed to show some efforts on your own.

again:
search Google with the keywords I wrote above,
find out some examples,
understand them,
modify them,
and then when you face problems, create a new thread in the programming section here using the code tags.

Last edited by Aquarius_Girl; 12-08-2010 at 03:22 AM. Reason: typo
 
Old 12-08-2010, 03:21 AM   #9
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
Chakki,

First you have to learn how the process works and communicates with the associated process. Download the below mentioned PDF and start working on it.

a.) Understanding The Linux Kernel (download from this link


Read and understand first. Later you can write your own source code easily.

Best Regards
 
Old 12-08-2010, 03:46 AM   #10
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
trying using man for associated c apis. man pages tent to have cone samples with the api explanations. They are not always well written documentations but They ship with almost any Linux system you can think of.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ipc between parent and child processes using pipe rainman1985_2010 Programming 3 10-15-2010 03:30 AM
IPC program sis650 Programming 1 04-27-2005 06:09 PM
IPC Memory Share - C Program - Why not exiting for(;;) ?? brunnopessoa Programming 4 09-05-2004 09:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration