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.
Hello, I will preface this with the fact I am a newbie.
I am running angstrom 3.2.0 on a AM335x kit. I have created an application with a thread that checks to see if a USB drive has been attached.
In the thread where I periodically check to see if the Usb Host has be mounted or not , I sleep.
I have a couple of questions.
1) should i use sleep(), nanosleep(), or pthread_yield()?
2) the other dumb question is i was expecting the application thread to be running in the background allowing me to continue using the command line. this is not the case, the command line is locked up while the application thread is running. is there anyway around this (i.e. i can run my application in the background and still have access to the command line?)
What I do when using threads is never assume a function is thread safe. Try as much as possible to use pthreads functions and to make sure other functions are thread safe.
Also, I would make sure that I really need a thread before starting one.
Again a dumb question. You mention to make sure that I really need a thread before starting one.
Like I mentioned, my application periodically checks to see if a USB drive is there and process accordingly. It only does this. So I only have one thread.
If I did not create a thread and just ran my code in a while loop in main. Does this just create a unique process? Are there any detrimental affects to the rest of my linux system running from doing this?
Should I use fork in the main application instead. That way I have access to the command line while mp application (process) is running?
Again a dumb question. You mention to make sure that I really need a thread before starting one.
Like I mentioned, my application periodically checks to see if a USB drive is there and process accordingly. It only does this. So I only have one thread.
If I did not create a thread and just ran my code in a while loop in main. Does this just create a unique process? Are there any detrimental affects to the rest of my linux system running from doing this?
Should I use fork in the main application instead. That way I have access to the command line while mp application (process) is running?
Thanks again.
I don't think you need a thread for this. Just run it in the main loop. As long as you let the system sleep using whatever sleep function you want, there should be no detrimental effects.
You can send a program to the background using '&' as mentioned above. It will output its pid in case you need to kill it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.