Sponsored Content
Full Discussion: synchronize as in java
Top Forums Programming synchronize as in java Post 48478 by Perderabo on Tuesday 9th of March 2004 06:32:36 AM
Old 03-09-2004
OK, use 7,564,263.

I'm tempted to end my reply there, but I guess some explanation is in order. Smilie

Suppose for a moment that your my_fn function was going to be used in a single executable so that the semaphore would only need to syncronize among simultaneous instances of that single executable. In that case, you could go ahead and use the address of the function. But what is magic about that address? The loader could, in theory, put another function in another executable at the same address.

There are billions of possible key values, but I have never seen a system that needs more than a few dozen. That makes this a small problem. Just pick something and go with that. It's like picking a name for your function or picking a file name.

Collisions are possible and you should be ready for them. Always test your return codes. And I would put the value in a config file and read it once. This makes it easy to change if that is ever needed. The my_fn could do this internally by using a static value initialized to zero. If zero, read the value and store it in the static variable.

Or you can just store the key as a constant in my_fn and risk the need to recompile should a collision occur. I've done that too.

There is also a function called ftok() that you should look at. It takes a pathname and a small integer and returns a key. I never use it, but if I don't mention it, someone else will. Smilie
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. Programming

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... (1 Reply)
Discussion started by: inabramova
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
SEM_GET(3)								 1								SEM_GET(3)

sem_get - Get a semaphore id

SYNOPSIS
resource sem_get (int $key, [int $max_acquire = 1], [int $perm = 0666], [int $auto_release = 1]) DESCRIPTION
sem_get(3) returns an id that can be used to access the System V semaphore with the given $key. A second call to sem_get(3) for the same key will return a different semaphore identifier, but both identifiers access the same underlying semaphore. PARAMETERS
o $key - o $max_acquire - The number of processes that can acquire the semaphore simultaneously is set to $max_acquire. o $perm - The semaphore permissions. Actually this value is set only if the process finds it is the only process currently attached to the semaphore. o $auto_release - Specifies if the semaphore should be automatically released on request shutdown. RETURN VALUES
Returns a positive semaphore identifier on success, or FALSE on error. CHANGELOG
+--------+-----------------------------------------+ |Version | | | | | | | Description | | | | +--------+-----------------------------------------+ | 4.3.0 | | | | | | | The $auto_release parameter was added. | | | | +--------+-----------------------------------------+ NOTES
Warning When using sem_get(3) to access a semaphore created outside PHP, note that the semaphore must have been created as a set of 3 sema- phores (for example, by specifying 3 as the nsems parameter when calling the C semget() function), otherwise PHP will be unable to access the semaphore. SEE ALSO
sem_acquire(3), sem_release(3), ftok(3). PHP Documentation Group SEM_GET(3)
All times are GMT -4. The time now is 07:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy