Find the answer to your Linux question:
Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By mizzle
Hello. My friends made a programming club in school, and I decided to join. The goal of the club is to make a Linux distro using Linuxfromscratch. The prime language ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Location
    Alderaan
    Posts
    11

    C++ and Linux


    Hello. My friends made a programming club in school, and I decided to join. The goal of the club is to make a Linux distro using Linuxfromscratch. The prime language we'll be coding in is C++. I know C++, but I want to learn more about its combination with Linux. If anyone would give me useful information on this topic, I thank you.

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    883
    In the Linux world, C and C++ are compile with gcc and g++ (part of the gcc package)
    Here's a simple primer: An Introduction to GCC - Compiling a simple C++ program

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,453
    Mizzle provides a good link. For more detailed documentation and FAQs, these are two important links:

    The Linux Documentation Project
    The Linux Kernel Archives

    The Linux kernel and device drivers are written in C and in some cases assembly language. The GNU Compiler Collection (GCC) can handle both. Many applications are written in C++. Learn C++ - it is a super-set of C - C with classes, allowing you to encapsulate behavior along with data structures. C++ can build/run pure C code without many problems. Unfortunately, C cannot build/run C++ code. IE, if you link C libraries and use C functions in C++ code, mostly it just works; however, the initializing code of a C and C++ program are quite different. IE, if you are going to link C++ functions/libraries into a C program, then you need to build your main() module with C++.

    Anyway, LFS is a great way to get familiar with the internals of Linux and how it all works together. Have a lot of fun! And do remember that we are here to help you over the rough spots!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Feb 2013
    Posts
    1
    hey i am new to linux and i am having problem with this question can anyone solve this ?
    1.Consider a pizza store which has 10 seats. A customer come to buy pizza. If there is any unsold pizza left in the kitchen, he can get it immediately. If not, (s)he need wait for chef to make one. After the customer gets the pizza, (s)he will grab a seat and start eating. If there is no seat, (s)he needs to wait. When (s)he finishes eating, (s)h will left the store. The chef in the kitchen just keeps making pizza. However, (s)he stops if there are 5 unsold pizza left in the kitchen. If a customer come to buy one, (s)he resumes the work to make new pizza. Please write pseudocode for both customer and chef using semaphore to solve this problem, and synchronize chef and customers.


    1. Write a multi-threaded program to solve producer and consumer problem.
     There are two types of worker thread: producer and consumer. A producer thread randomly generate an integer between 0-100 (You can use random()/srandom() or drand48()/srand48() to generate random number in C), and put it into the buffer. A consumer thread simple take the first integer from the buffer. A circular array should be used for the buffer. You do not need loop for both types of thread. Each thread will exit after only consuming or producing one item (only once).
     Assume total number of worker thread is 20, and buffer size is 10. Your program should randomly generate the number of producers and consumers. Their relationship should be : num_producers + num_consumers = num_threads, num_producer - num_consumer <= buffer_size, num_consumer <= num_producer, so that no thread will be blocked forever. The order between consumer and producer threads should be arbitrary. For example, you shall not generate all producers(consumers) and then all consumers (producers).
     Synchronize the producer and consumer.
     You can choose any type of language (e.g. C/C++/Java) to implement this program. Your output will look like the following:
    Number of producer: 12 Number of consumer: 8
    Thread 0 produce 63 in buffer 0, current number of items is 1
    Thread 1 consume item 63 in buffer 0, current number of items is 0
    Thread 3 produce 45 in buffer 1, current number of items is 1
    Thread 5 produce 88 in buffer 2, current number of items is 2
    Thread 4 consume item 45 in buffer 1, current number of items is 0
    …....
    …..
    …...
    There are still 4 items left in the buffer: 96,26,52,81

     more reference about pthread library if you choose to use it.

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,453
    Quote Originally Posted by aki007 View Post
    hey i am new to linux and i am having problem with this question can anyone solve this ?
    1.Consider a pizza store which has 10 seats. A customer come to buy pizza. If there is any unsold pizza left in the kitchen, he can get it immediately. If not, (s)he need wait for chef to make one. After the customer gets the pizza, (s)he will grab a seat and start eating. If there is no seat, (s)he needs to wait. When (s)he finishes eating, (s)h will left the store. The chef in the kitchen just keeps making pizza. However, (s)he stops if there are 5 unsold pizza left in the kitchen. If a customer come to buy one, (s)he resumes the work to make new pizza. Please write pseudocode for both customer and chef using semaphore to solve this problem, and synchronize chef and customers.


    1. Write a multi-threaded program to solve producer and consumer problem.
     There are two types of worker thread: producer and consumer. A producer thread randomly generate an integer between 0-100 (You can use random()/srandom() or drand48()/srand48() to generate random number in C), and put it into the buffer. A consumer thread simple take the first integer from the buffer. A circular array should be used for the buffer. You do not need loop for both types of thread. Each thread will exit after only consuming or producing one item (only once).
     Assume total number of worker thread is 20, and buffer size is 10. Your program should randomly generate the number of producers and consumers. Their relationship should be : num_producers + num_consumers = num_threads, num_producer - num_consumer <= buffer_size, num_consumer <= num_producer, so that no thread will be blocked forever. The order between consumer and producer threads should be arbitrary. For example, you shall not generate all producers(consumers) and then all consumers (producers).
     Synchronize the producer and consumer.
     You can choose any type of language (e.g. C/C++/Java) to implement this program. Your output will look like the following:
    Number of producer: 12 Number of consumer: 8
    Thread 0 produce 63 in buffer 0, current number of items is 1
    Thread 1 consume item 63 in buffer 0, current number of items is 0
    Thread 3 produce 45 in buffer 1, current number of items is 1
    Thread 5 produce 88 in buffer 2, current number of items is 2
    Thread 4 consume item 45 in buffer 1, current number of items is 0
    ....
    ..
    ...
    There are still 4 items left in the buffer: 96,26,52,81

     more reference about pthread library if you choose to use it.
    1. Don't hijack another person's thread.
    2. Read the terms of service for the forums - we don't help you with school assignments/problems.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •