Thread: IPC shared memory and threads

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    Exclamation IPC shared memory and threads

    i want to create program with a size 10 and then create and array and put the values entered thru keyboard and store it.here it asks the user to enter the size of the array and then enter integer numbers.

    consumer we have to get the array and print it in the consumer


    can somebody PLZZZZZZZZZZZZZZZZZZZZZZZZZZZ HELP MEE





    #include<sys/types.h>
    #include<sys/ipc.h>
    #include<sys/shm.h>
    #include<stdio.h>

    #define SHMSZ 10

    main()
    {
    int a;
    int shmid;
    int *shm;
    key_t key;
    int u;
    int i;
    printf("enter array size\n");
    scanf("%d",&u);


    int* arrray=(int*) malloc(sizeof(int) * user);

    key = 1234;

    if((shmid = shmget(key,SHMSZ, IPC_CREAT | 0666)) < 0)
    {
    perror("shmget");
    exit(1);
    }

    if((shm = shmat (shmid, NULL, 0)) == (int *) -1)
    perror("shmat");
    exit(1);
    }




    a =shm;

    for(i = 0; i<user;i++)
    { scanf("%d",&a);
    array[i]=a;
    }

    *ar = NULL;

    while(*shm != '*')
    sleep(1);

    exit(0);

    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    There seems to be a plethora of idiots unable to either comprehend forum posting rules OR figure out what to do with a "use code tags" popup when they post code without code tags.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User Kudose's Avatar
    Join Date
    Jun 2006
    Posts
    92
    I had to bite my tongue when I saw a post from someone in a developing country asking for the complete code from people they are taking jobs from.
    IDE + Complier: Code::Blocks w/ GCC
    PC: AMD Phenom x4 2.2Ghz w/ 8G RAM
    OSes: CentOS 6.2 x64 & Win 7 Ultimate x64

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Kudose View Post
    I had to bite my tongue when I saw a post from someone in a developing country asking for the complete code from people they are taking jobs from.
    Unless you want to move away from a capitalist economic system, that is the situation you are stuck with. If I am willing to do your job for less money you are obsolete.

    In that case, making a distinction based on where someone is located is (still) foolish -- you should not offer help or advise to anyone at all, because anyone could just as easily do the same thing. You will be worth more money if you can keep everything secret from everyone.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Leaking memory when creating threads
    By Elkvis in forum Windows Programming
    Replies: 3
    Last Post: 08-18-2009, 02:27 PM
  2. POSIX Threads and dynamic memory allocation
    By PING in forum Linux Programming
    Replies: 1
    Last Post: 04-02-2009, 10:28 AM
  3. BSD mmap for shared memory - am I right?
    By sean in forum Linux Programming
    Replies: 21
    Last Post: 03-09-2009, 01:57 PM
  4. Shared memory implementation using thread
    By kumars in forum C Programming
    Replies: 5
    Last Post: 06-18-2008, 04:24 AM
  5. using shared memory in c
    By flawildcat in forum C Programming
    Replies: 1
    Last Post: 04-09-2002, 12:25 PM