Any similar function as Arduino's delay() in Linux C program?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Since your program is not alone on a Linux system, you need to be aware that the sleep time is not that accurate:
In general, how much off will that be? Less than a second, 500ms, 10ms, 1ms? Are there ways to achieve more accurate results? For example, getting some kind of stopwatch...
Will keep pulling the time (e.g. date command on linux. not sure about C's function to access it) and checking the difference to see if x msec has passed work better?
Last edited by brownlinux; 10-11-2020 at 04:51 PM.
In general, how much off will that be? Less than a second, 500ms, 10ms, 1ms? Are there ways to achieve more accurate results? For example, getting some kind of stopwatch...
Will keep pulling the time (e.g. date command on linux. not sure about C's function to access it) and checking the difference to see if x msec has passed work better?
You could use gettimeofday as in the above link. It's worth a try, but you should also explore realtime priorities to mitigate the above factors.
Last edited by berndbausch; 10-11-2020 at 05:34 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.