Sponsored Content
Top Forums Programming need a way to synchronize processes Post 302177079 by inabramova on Thursday 20th of March 2008 01:34:57 AM
Old 03-20-2008
need a way to synchronize processes

I am writing a program in C for my networking class, so I am relatively new to this.
To begin, I have 7 processes that need do send messages to every other one, and every one of them needs to receive the messages sent by others.

I am using fork() to create 6 more processes.
The message sending should be done through UDP sockets. So I create 6 sockets for sending using bind() and then I do sendto()

After that the processes call receivefrom()
The problem is that sometimes the process does not catch the sent message, and so the program keeps on waiting for the rest of messages.
I try to rearrange sending and receiving, but ofcourse the scheduler does its own thing. I realize it needs a way to make them wait for each other, I am just not sure how to do it.

Thank you for any help!
 

9 More Discussions You Might Find Interesting

1. Programming

synchronize as in java

Hi, I am trying to implement the synchronize feature of java using C. I am using a semaphore for the same. I have a wrapper called "synch" to which I pass the function pointer(any_fn). This pointer points to the function (my_fn) which needs to be synchronized. However to create the semaphore I... (8 Replies)
Discussion started by: linuxpenguin
8 Replies

2. Shell Programming and Scripting

How to synchronize all the linux machine?

Hi, I have three Linux machine have three different times. Can I synchronize them using one process? I have root access. Thanks! (1 Reply)
Discussion started by: whatisthis
1 Replies

3. Shell Programming and Scripting

how to synchronize different dirs

I have 4 directory Dir1 file1 file2 file3 file4 Dir2 file3 file5 file6 file8 Dir3 file1 file2 file6 file9 file10 Dir4 file3 file6 file12 file15 and all the 4 dirs are having couple of files. Few of the files are common to other directory/ies and few... (1 Reply)
Discussion started by: reldb
1 Replies

4. UNIX for Advanced & Expert Users

synchronize processes

hi. i am writing a c program under bash shell. i would like to use semaphore functions like sem_wait(), sem_post() and i included <semaphore.h> and it compailes fine but when i try to run it gives me an error "undefined reference to sem_wait() , sem_post() , sem_init()" what have i missed... (2 Replies)
Discussion started by: emil2006
2 Replies

5. Programming

synchronize two processes

i am trying to synchronize between father process and son process created by fork() command, to print simultaneously. my program is written in c under bash shell. the compile goes ok but when i try to run nothing happens and the program doesnot end. my code is: #include <stdio.h>... (1 Reply)
Discussion started by: emil2006
1 Replies

6. Shell Programming and Scripting

Synchronize Files-Help

Hi, I have two servers1&2, one is not in the network. Cant communicate from it to other servers. The second one can communicate to above mentioned server. I am trying a script which synchronizes files between server 1 an 2? server1: cant communicate to any other servers server2: can... (4 Replies)
Discussion started by: Tuxidow
4 Replies

7. Shell Programming and Scripting

How to synchronize using FTP

Hi everyone! I need to write a script that will synchronize two servers using FTP. So basically the script will get only the files that exist on the remote server that do not exist on the local server. Is there an option to do this when using mget? If not, is there a way to copy over only the... (2 Replies)
Discussion started by: Fatbob
2 Replies

8. AIX

Verify and Synchronize HACMP

Hi Earlier we used to move the resource groups between nodes manually. Recently I have added the HACMP startup and stop scripts. Then I moved the resource group to see if everything works fine as per the startup and stop scripts, but it didn't work out as expected. Do i need to do bring... (4 Replies)
Discussion started by: samsungsamsung
4 Replies

9. UNIX for Advanced & Expert Users

How to synchronize two different files?

Hello, I have the latest stable release of a UNIX-like O.S. in the ISO format, and want to synchronize it with the latest Release Candidate (RC) of it, in order to reducing bandwidth usage. The ISO images for that O.S. is provided via different protocols including rsync, FTP and HTTP Is this... (4 Replies)
Discussion started by: temp-usr
4 Replies
NG_SOCKET(4)						   BSD Kernel Interfaces Manual 					      NG_SOCKET(4)

NAME
ng_socket -- netgraph socket node type SYNOPSIS
#include <sys/types.h> #include <netgraph/ng_socket.h> DESCRIPTION
A socket node is both a BSD socket and a netgraph node. The ng_socket node type allows user-mode processes to participate in the kernel netgraph(4) networking subsystem using the BSD socket interface. The process must have root privileges to be able to create netgraph sockets however once created, any process that has one may use it. A new ng_socket node is created by creating a new socket of type NG_CONTROL in the protocol family PF_NETGRAPH, using the socket(2) system call. Any control messages received by the node and not having a cookie value of NGM_SOCKET_COOKIE are received by the process, using recvfrom(2); the socket address argument is a struct sockaddr_ng containing the sender's netgraph address. Conversely, control messages can be sent to any node by calling sendto(2), supplying the recipient's address in a struct sockaddr_ng. The bind(2) system call may be used to assign a global netgraph name to the node. To transmit and receive netgraph data packets, a NG_DATA socket must also be created using socket(2) and associated with a ng_socket node. NG_DATA sockets do not automatically have nodes associated with them; they are bound to a specific node via the connect(2) system call. The address argument is the netgraph address of the ng_socket node already created. Once a data socket is associated with a node, any data pack- ets received by the node are read using recvfrom(2) and any packets to be sent out from the node are written using sendto(2). In the case of data sockets, the struct sockaddr_ng contains the name of the hook on which the data was received or should be sent. As a special case, to allow netgraph data sockets to be used as stdin or stdout on naive programs, a sendto(2) with a NULL sockaddr pointer, a send(2) or a write(2) will succeed in the case where there is exactly ONE hook attached to the socket node, (and thus the path is unambigu- ous). There is a user library that simplifies using netgraph sockets; see netgraph(3). HOOKS
This node type supports hooks with arbitrary names (as long as they are unique) and always accepts hook connection requests. CONTROL MESSAGES
This node type supports the generic control messages, plus the following: NGM_SOCK_CMD_NOLINGER When the last hook is removed from this node, it will shut down as if it had received a NGM_SHUTDOWN message. Attempts to access the sockets associated will return ENOTCONN. NGM_SOCK_CMD_LINGER This is the default mode. When the last hook is removed, the node will continue to exist, ready to accept new hooks until it is explic- itly shut down. All other messages with neither the NGM_SOCKET_COOKIE or NGM_GENERIC_COOKIE will be passed unaltered up the NG_CONTROL socket. SHUTDOWN
This node type shuts down and disappears when both the associated NG_CONTROL and NG_DATA sockets have been closed, or a NGM_SHUTDOWN control message is received. In the latter case, attempts to write to the still-open sockets will return ENOTCONN. If the NGM_SOCK_CMD_NOLINGER message has been received, closure of the last hook will also initiate a shutdown of the node. SEE ALSO
socket(2), netgraph(3), netgraph(4), ng_ksocket(4), ngctl(8) HISTORY
The ng_socket node type was implemented in FreeBSD 4.0. AUTHORS
Julian Elischer <julian@FreeBSD.org> BUGS
It is not possible to reject the connection of a hook, though any data received on that hook can certainly be ignored. The controlling process is not notified of all events that an in-kernel node would be notified of, e.g. a new hook, or hook removal. Some node-initiated messages should be defined for this purpose (to be sent up the control socket). BSD
January 19, 1999 BSD
All times are GMT -4. The time now is 11:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy