Window Linux IPC ftok by_handle_file_information

Source: Internet
Author: User

Look at the problem is very chaotic, the mood is not very good, of course. Some time ago, a project was made, one of the AIX (Unix) systems migrated to Windows, and the development environment was created by the IBM C/s + + (called What forgot, as if xlc) became VC + +.

This is calculated, but the recent process communication signal volume is out of the question (nor what is the problem, that is, the global semaphore name should be named a bit of a problem. )

In Aix systems, the name of the semaphore is actually key_s (essentially int), and key_s is returned by Ftok. The approximate logic is to specify the files that exist on a system, take the low 24 bits of the index node number of the file, and then use the offset field for the high 8 bits.

This allows the same system file to generate up to 256 semaphore names.

But Windows does not have this, Windows just need to specify a string to do it. But the string prefix can be golbal, local, none, three cases, because the difference in Semaphore is global, locally, default (local).

Then I used the file name (without the path) to generate a semaphore name, because I did not really find the Windows File Index node number (there is no concept at all, well I admit to be cheated by the Niang of a penny left).

Then I led this Japanese Yahoo really found the corresponding concept of Windows side, is by_handle_file_information, in fact, when the Aix file is stored using the device number + file number, and Windows is

Using the device number + file number high + file number status to store, should be counted as a correspondence relationship. (IPC is also available on the Windows side, but both the device number and the file number are 0)

 typedef struct _BY_HANDLE_FILE_INFORMATION {DWORD    dwFileAttributes;  FILETIME Ftcreationtime;  FILETIME Ftlastaccesstime;  FILETIME Ftlastwritetime;  DWORD      Dwvolumeserialnumber ;  DWORD    nFileSizeHigh;  DWORD    nFileSizeLow;  DWORD    nNumberOfLinks;  DWORD      Nfileindexhigh ; DWORD      nfileindexlow ;} By_handle_file_information, *pby_handle_file_information, *lpby_handle_file_information; The 

is bold and is defined. Using this is a single file that can be uniquely identified by 3 DWORD (also understood to be an int). If the file does not exist, it is-1 (0xffffffff in memory). The
then needs to explain that the signal name in Windows is preferably "xxxx-xxxxxxxx-xxxxxxxxxxxxxxxx" (offset-Device number-file number) in this form.
How to get _by_handle_file_information:
----Get fi----
HANDLE h = invalid_handle_value;
By_handle_file_information fi;
h = CreateFile (path, 0, 0, NULL, open_existing, 0, NULL);
GetFileInformationByHandle (H, &fi);
----Get fi----

Window Linux IPC ftok by_handle_file_information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.