ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
For POSIX timer, we can get a timer ID by calling timer_create. After checked man, timer ID may be any value including zero. But when our guy mistake to call timer_delete with zero as timer ID, crash happen with timer_delete, as core dump file. Can anyone confirm the issue? In addition, we are using tool-chain v4.1.
The kernel uses an integer value to uniquely identify each new timer.
It starts counting and goes on. It is theoretically possible for the number to rollover, ie., 0xffffffff -> 0. I do not know if Linux kernels support this. Plus, this would require using a LOT of timers on a system that was up for a very long time.
If your code tries to access a non-existent timer, it will dump core. Is that what you're asking? You do realize that what you describe is a coding error, not a kernel problem.
The kernel uses an integer value to uniquely identify each new timer.
It starts counting and goes on. It is theoretically possible for the number to rollover, ie., 0xffffffff -> 0. I do not know if Linux kernels support this. Plus, this would require using a LOT of timers on a system that was up for a very long time.
If your code tries to access a non-existent timer, it will dump core. Is that what you're asking? You do realize that what you describe is a coding error, not a kernel problem.
First thanks for your reply.
In addition, as your reply, zero may be a timer ID. Am I right?
So, as man timer_delete, if a invalid timer ID is inputted like my case, a error code should be returned instead of crash. Actually I mistook to input zero as timer ID to timer_delete, i.e. I used a invalid timer ID, so a error code should be returned in such case. Is my understanding correct?
int timer_create(clockid_t clockid, struct sigevent *restrict evp, timer_t *restrict timerid);
"If the call succeeds, timer_create() shall return zero and update the location referenced by timerid to a timer_t, which can be passed to the per-process timer calls. If an error occurs, the function shall return a value of -1 and set errno to indicate the error. The value of timerid is undefined if an error occurs."
It's the return value of timer_create you have to check before you try to use the timerid in timer_delete(), because if you pass an invalid timer id to timer_delete it might/will crash, not return an error.
Code:
pseudocode
int retvalue timer_create(..., ..., &timerid);
if(retvalue == -1)
{
print the error
maybe exit
}
else
{
do something with the timer
...
time to delete the timer
retvalue = timer_delete(timerid);
if(retval == -1)
{
print error message, e.g "Failed to delete timer"
}
}
Yes according to man, timer_delete should return EINVAL, not crash (did you try to do anything else than timer_delete with the invalid timer?), (note: I haven't tried it myself).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.