Msgget ()
System Call msgget ()
If you want to create a new message queue or access an existing message queue, you can use the system to call msgget ().
System Call: msgget ();
Prototype: intmsgget (key_t key, int msgflg );
Returned value: if the message is successful, the Message Queue identifier is returned.
If the request fails,-1: errno = eaccess is returned (the permission is not allowed)
Eexist (the queue already exists and cannot be created)
Eidrm (the queue mark is deleted)
Enoent (the queue does not exist)
Enomem (insufficient memory when creating a queue)
Enospc (exceeds maximum queue limit)
The first parameter in msgget () is the keyword value (usually returned by ftok ). The keyword value is then compared with other key values that already exist in the system kernel. In this case, the open and access operations are related to the content in the msgflg parameter.
Ipc_creat: If this queue does not exist in the kernel, it is created.
When ipc_excl is used with ipc_creat, if the queue already exists, it fails.
If ipc_creat is used separately, msgget () returns either the identifier of a newly created message queue or the identifier of a queue with the same keyword value. If ipc_excl and ipc_creat are used together, msgget () will either create a new message queue or return a failure value-1 if the queue already exists. Ipc_excl is useless when used independently.
The following is an example of opening and creating a message queue:
Export pen_queue (key_t keyval)
{
Intqid;
If (qid = msgget (keyval, ipc_creat | 0660) =-1)
{
Return (-1 );
}
Return (qid );
}
Bytes ---------------------------------------------------------------------------------------------------
Description of each field in the TM Structure
Description of each field in the TM Structure
Each segment in the TM structure is of the int type.
Tm_sec second]
Tm_min minutes]
Tm_hour hour [0, 23 ]. The timer starts from midnight. In UTC, the Greenwich Mean is used as the standard 0, and in local, the local time zone is used as the standard 0.
Gmtime returns UTC and localtime returns local.
Tm_mon month [0, 11 ]. Note that the values are from 0 to 11, rather than from 1 to 12.
The year of tm_year. It was calculated from January 1, 1900. That is, the difference between this year and 1900 is recorded.
Tm_wday indicates the day of a week]
Tm_yday indicates the day of the year [0,365], and January 1 is 0
Tm_isdst is not clear. In this document, the value is 0 in gmtime.
========================================================== =
Struct TM
{
Int tm_sec;/* seconds. [0-60] (1 leap second )*/
Int tm_min;/* minutes. [0-59] */
Int tm_hour;/* hours. [0-23] */
Int tm_mday;/* day. [1-31] */
Int tm_mon;/* month. [0-11] */
Int tm_year;/X year-1900 .*/
Int tm_wday;/* day of week. [0-6] */
Int tm_yday;/* Days in year. [0-365] */
Int tm_isdst;/* DST. [-1/0/1] */
# Ifdef _ use_bsd
Long int tm_gmtoff;/* seconds east of UTC .*/
_ Const char * tm_zone;/* timezone abbreviation .*/
# Else
Long int _ tm_gmtoff;/* seconds east of UTC .*/
_ Const char * _ tm_zone;/* timezone abbreviation .*/
# Endif
};
In C Language
There are time_t TM timeval and other types of time
1. time_t is typedef _ int64 _ time64_t;
2. struct timeval
{
Uint TV _sec;
Uint TV. USEC;
}
Specific operation functions
File Inclusion: <sys/time. h> <time. h>
TM * gmtime (time_t * t );
Time_t time (time_t * t );
Char * asctime (const struct TM * timeptr );
Char * ctime (const time_t * timer );
Convert TM pointer to time_t
Time_t mktime (struct TM * timeptr );
The difference between localtime and gmtime is that gmtime converts time to an international standard format, that is, the timestamp starting from 1970 00:00:00.
Localtime is relative to the local time zone.
# Include <stdio. h>
# Include <time. h>
# Include <sys/time. h>
# Include <signal. h>
# Include <pthread. h>
Void quit_t ()
{
Printf ("eixt now ");
Exit (-1 );
}
Int main ()
{
/* Struct timeval VT;
Gettimeofday (& VT, null );
While (1)
{
Printf ("% u: % u/N", vt. TV _sec, vt. TV _usec );
Sleep (2 );
Signal (SIGINT, quit_t );
}
*/
Struct TM * tt;
Time_t t = time (null );
Tt = gmtime (& T );
// Char * s = asctime (TT );
Printf ("% d-% d: % d", TT-> tm_year + 1900, TT-> tm_mon + 1, TT-> tm_mday, TT-> tm_hour, TT-> tm_min, TT-> tm_sec );
Return 0;
}