Sponsored Content
Top Forums Programming Two player game, forking & sockets Post 302528696 by Shang on Tuesday 7th of June 2011 06:06:08 PM
Old 06-07-2011
Quote:
Originally Posted by Corona688
Any particular reason? It's the same thing in the end, just a lot more convoluted.
I read on stackoverflow.com that it is more portable. I have no particular must, just curiosity, I am also reading about POSIX ones.
Quote:
Originally Posted by Corona688
Do the games inherit shared memory for the parent or not? When you fork(), shared memory is inherited, so if the parent had it the children will start off with it and not need to fool with shmat().
Oh, I haven't noticed that fact. Good to know.
Quote:
Originally Posted by Corona688
You have to store the contents in the shared memory, never heap pointers.
Ok, I will remember that.
Quote:
Originally Posted by Corona688
Even pointers to the shared memory might not work unless every process maps the memory in the exact same place.
Do you mean that below code is wrong?
Code:
int shm;
key_t key;
game_state *gsbuf;

if((key = ftok(".",'s')) < 0) ERR("ftok"); // still don't know why here is 's', copied from some webpage
shm = makeshm(sizeof(gsbuf), key);
if((gsbuf = shmat(shm, NULL, 0)) == (void *) -1) ERR("shmat");

/* then some forking */

(...)

/* outside main */
int makeshm(size_t size, key_t key) {
    int shm;
    if((shm = shmget(key,size,IPC_CREAT|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH))<0)
         ERR("Create shared memory");
    return shm;
}

Quote:
Originally Posted by Corona688
Just make a big enough memory segment in the first place and the OS will dynamically allocate more pages as you use them.
I think that is my problem. What does it mean big enough? Server doesn't know how much clients would have. The main point is how to organize this shared memory to grow as new games are started.
Quote:
Originally Posted by Corona688
That could be a ridiculous number of semaphores for a lot of clients, though. You could have an integer stored in shared memory of whose turn it is, and when a client is created they poll it until they're told it's their turn, then they sem_wait()/sem_post()/sem_wait()/sem_post()... I think the order would remain stable after that.
Good idea, thanks Smilie
Quote:
Originally Posted by Corona688
As for your game structure -- instead of a structure full of big arrays, how about a big array of structures?
I am not sure if I understand well. Could you propose any sketch?
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Association b/w sockets & processes

Hi, Is there any way i can know the association between sockets and the processes which created them. :confused: (5 Replies)
Discussion started by: soorajmu
5 Replies

2. Linux

Having player problem && need your help.

My System is FC3, The following Players don't run well: 1).Helix Player couldn't play MP3 and *.wma files, 2).Totem is the same, 3)XMMS couldn't play .wma files. I am a newer of Linux,but I like Linux,just as you. Could you help me? Thank you! (1 Reply)
Discussion started by: letcorpmuv
1 Replies

3. Programming

Forking in a loop

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation. Because I am stuck with this. #include <stdio.h> main(){ int i = 0; printf("I am the... (1 Reply)
Discussion started by: manjuWicky
1 Replies

4. UNIX for Advanced & Expert Users

Forking

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation with the schedular functionality it will help a lot. Because I am stuck with this. #include <stdio.h> main(){... (3 Replies)
Discussion started by: manjuWicky
3 Replies

5. HP-UX

Mozilla & Macromedia Flash Player Plugin Problem

Hello All, I am using Mozilla 1.7.8 on hp-ux 11.00, and install flash player 6 for it. it is giving following errors and get crashed. when i want to open a site need flash plugin. Gtk-WARNING **: invalid cast from `GtkSuperWin' to `GtkWidget' Gtk-WARNING **: invalid cast from `GtkSuperWin'... (1 Reply)
Discussion started by: Awadhesh
1 Replies

6. Programming

forking within a thread

Is it safe to call fork+exec in a multithreaded application. Because In my multithreaded application, I need to execute another program in each thread. I am using solaris 10. Any suggestions pls. (2 Replies)
Discussion started by: axes
2 Replies

7. Programming

need help in forking

I have an input file with contents like: 5785690|68690|898809 7960789|89709|789789 7669900|87865|659708 7869098|65769|347658 so on.. I need to pass this file to 10 parallely running processes (forking)so that each line is processed by a process and no line is processed twice and write the... (1 Reply)
Discussion started by: rkrish
1 Replies

8. Linux

Unable to install VLC media player or any other player in SL 6.3 distro

Hi, I am unable to install VLC or any other media players in my SL 6.3 distro. I am using yum utility to install the packages, but i am getting the below error messages, --> Processing Dependency: libpng15.so.15()(64bit) for package: vlc-core-2.0.3-1.fc18.x86_64 --> Processing... (1 Reply)
Discussion started by: vel4ever
1 Replies
All times are GMT -4. The time now is 04:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy