Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
printf("the ret value is %d",ret);
printf("cannot open number.txt");
printf("the line no is %d buff1 is %s",read1,buff1);
void *starting_point(void *arg)
printf("cannot open the file");
printf("bytes read is %d buff is %s",read,buff);
It isn't clear why you are using threads to do this?
If you have to do it with semaphores, then you would need two semaphores, each one granting the other task its turn (so that they take it in turns). Using only one semaphore, it is not determinable which task will get access (typically the first task will just use up its timeslice and complete everything before the second task gets a look in). You have also put the join in the wrong place (you are calling join inside the loop instead of at the end).
Alternatively you could use an access semaphore (so that they don't write to the output at the same time), and a pthread_barrier to synchronize them as they loop through the lines of the files. This is a less portable method (ie, most systems have semaphores, but not all have a barrier primitive).