Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F67050293
timerfd.c
vico.chern_qq.com (Vico Chen)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
vico.chern_qq.com
Sep 4 2023, 3:28 AM
2023-09-04 03:28:00 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
timerfd.c
View Options
#include
<signal.h>
#include
<assert.h>
#include
<stddef.h>
#include
<stdio.h>
#include
<errno.h>
#include
<signal.h>
#include
<stdlib.h>
#include
<stdint.h>
#include
<stdbool.h>
#include
<string.h>
#include
<fcntl.h>
#include
<sys/socket.h>
#include
<sys/un.h>
#include
<sys/epoll.h>
#include
<sys/signalfd.h>
#include
<sys/timerfd.h>
#include
<unistd.h>
#include
<poll.h>
#include
<pthread.h>
int
main
(
int
argc
,
char
**
argv
)
{
int
counter
=
0
;
int
n
=
0
;
int
err
=
0
;
int
tmfd
=
0
;
struct
itimerspec
its
;
struct
pollfd
pd
;
printf
(
"TFD_CLOEXEC=%x, TFD_NONBLOCK=%x.
\n
"
,
TFD_CLOEXEC
,
TFD_NONBLOCK
);
tmfd
=
timerfd_create
(
CLOCK_MONOTONIC
,
TFD_CLOEXEC
|
TFD_NONBLOCK
);
//tmfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
if
(
tmfd
<
0
)
{
printf
(
"tmfd=%d
\n
"
,
tmfd
);
return
-1
;
}
its
.
it_interval
.
tv_sec
=
0
;
its
.
it_interval
.
tv_nsec
=
0
;
its
.
it_value
.
tv_sec
=
1
;
its
.
it_value
.
tv_nsec
=
1
;
err
=
timerfd_settime
(
tmfd
,
0
,
&
its
,
NULL
);
printf
(
"err=%d...
\n
"
,
err
);
pd
.
fd
=
tmfd
;
pd
.
events
=
POLL_IN
;
pd
.
revents
=
0
;
do
{
pd
.
revents
=
0
;
printf
(
"Polling...
\n
"
);
n
=
poll
(
&
pd
,
1
,
-1
);
if
(
n
<
0
)
continue
;
++
counter
;
printf
(
"Get one: #%d, n=%d, revents=0x%x
\n
"
,
counter
,
n
,
pd
.
revents
);
timerfd_settime
(
tmfd
,
0
,
&
its
,
NULL
);
}
while
(
1
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6305949
Default Alt Text
timerfd.c (1 KB)
Attached To
Mode
D41708: Linux ABI timerfd can't work on FreeBSD 14 stable.
Attached
Detach File
Event Timeline
Log In to Comment