2013年10月10日星期四

Help: XSI IPC communication on the process identifier key difference

[color = # FF0000] to ask questions in the IPC identifier and key differences , the book says that the former is the IPC object's internal name , the latter is the external name , which god can you give a concrete example of the use of these two ? online for a long time not found . . . Younger to be grateful ! ! ! [/ color]
------ Solution -------------------------------- ------------
descriptor for the purposes of user actions , allowing users to manipulate and feel the same operation on the file , the keys are inside the system say. Why do we need specific keys I was not very clear , I am sorry , and so great God to answer it. . . .
------ For reference only -------------------------------------- -
int qid; / * message queue identifier * /
30 int msglen;
31 key_t msgkey;
32
33 / * Get the key * /
34 if ((msgkey = ftok (PATH_NAME, PROJ_ID)) == - 1 ) {
35 perror ("ftok error! \ n");
36 exit (1);
37}
38
39 / * create a message queue * /
40 if ((qid = msgget (msgkey, IPC_CREAT | 0660)) == -1 ) {
41 perror ("msgget error! \ n");
42 exit (1);
43}

This is the use of specific methods , in creating a message queue ( other ipc same ) , you need to pass the file path name and project ID to get a key, then this key identifier generated by the kernel , in the future through this identifier to use this message queue.

------ For reference only ---------------------------------- -----
Hello baihualin497, first of all very grateful to you for your enthusiastic answer my question ! advice to you then , why have a key it ? For example, through the use of an ordinary file descriptor is enough why both the IPC key identifiers also have to do ? On the book is an external , one internal . . . That means outside in the end is what ?
------ For reference only ------------------------------------ ---
As for the internal and external , should the kernel and user processes refers to the points it
------ For reference only ------------------ ---------------------
As internal and external , should refer to the kernel and user processes
------ For reference only - -------------------------------------
Thank baihualin497 your enthusiastic answer ; and be grateful :) ! ! !
------ For reference only -------------------------------------- -
Frankly , paste a little content. . .
Yesterday and others to discuss the next, tentatively conclude that :
We use ftok to create keys, you can man about fotk specific function , something like this : at a given path name to obtain its stat structure from the structure and remove the part st_dev st_ino field and then with project id combined , if two pathnames refer to two different files , then called with the pathname of these two different keys ftok usually returns , however, because the i-node number and the key is usually stored in a long integer , the so may be lost when creating the key information, which means that , if the same item id, then the two paths for different file name may generate the same key.

do not know that you know not
------ For reference only --------------------------- ------------
" because the i-node number and the keys are usually stored in a long integer , the result may be lost when you create the key message" ----- understanding of this sentence Why i-node number and the keys are usually stored in a long integer will result in the creation of key information may be lost ? Data is not to say that too much information may lead to a long integer can not be completely stored ? Or some other means ? :)
------ For reference only ---------------------------------- -----
key type is key_t, is an int , long integer if the content stored outside the range of int type , it may lose data.
------ For reference only -------------------------------------- -
Thank you for your patience baihualin497 answer :)
------ For reference only --------------------- ------------------
 good

没有评论:

发表评论