Beginners programming in linux

Linux Programming Made Easy – A Complete Guide With Resources For Beginners

Updated June 18, 2021

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

Linux is an operating system, platform, ecosystem, and culture. While the continued dominance of Windows and Mac OS for desktop computing causes the uninitiated consumer to assume that Linux is a sort of fringe option for extreme geeks and those who don’t want to pay for an operating system, the truth of the matter is that Linux is the most used and most important operating system on the planet. It powers the web, it powers our infrastructure, it powers the largest supercomputers in the world.

Developing for Linux can be a bit of a challenge, but it can also be extremely rewarding. This short guide will provide you with an introduction to the information and resources you need to get started with Linux programming. It covers four areas of Linux development: contributing to the kernel, building new modules, developing applications for Linux, and Shell scripting.

Need Web Hosting?

If you’re in the market for a new web hosting provider, be sure to check out our user reviews, our A-Z hosting guide and our top three popular hosting picks:

Linux kernel development

The Linux kernel is, perhaps, the most ambitious software development project on the planet. New stable releases come out approximately every three months, and each release involves thousands of developers working in dozens of countries.

Getting involved with kernel development is, paradoxically, both easier than it seems like it should be, and also ridiculously difficult. It is easier than it seems like it should be, because there is no hiring process, no interview, no bureaucracy. Anyone who knows what they are doing is welcome to develop for the core, and submit patches. On the other hand, it is also extremely difficult because the kernel is extremely complicated. Moreover, the kernel development community, while quite welcoming in some ways, does not tolerate amateur shenanigans very well. While it helps to have thick skin, nothing really substitutes for actually knowing what you are doing. Developing the core is pretty serious business, involving pretty serious computer science. If you are just getting started with operating system development, this is not really the place to start.

What You Need to Know

Development Skills

Programming of the Linux kernel is done in C. Not C++, not Objective-C, not C#. So the first thing that you need to do is learn the C programming language extremely well.

You also need to have a deep understanding of operating system theory, particularly as it relates to the Linux system. More on that in the next section.

  • The C Programming Language: the definitive guide to the language. Also available as a free PDF.
  • Operating System Concepts: a thorough introduction to the theory and practice of operating system development.
Читайте также:  Portable vpn client windows 10

Understanding Linux

Naturally, you need to understand Linux both as a user and as a developer. This includes having a fairly deep understanding of how the Linux kernel is structured, and how the various sub projects fit together.

Process and Culture

Finally, you need to understand how the Linux development process actually works. This includes getting a feel for the community as a whole, for its culture, and how the various members of the development community relate to each other. Also, it means understanding distributed version control, and the development release cycle.

  • How to Participate in the Linux Community: required reading. Start here.
  • Three Ways for Beginners to Contribute to the Linux Kernel: a short, friendly guide to getting involved.
  • Official Things:
    • The Linux Kernel Archives
    • The Linux Kernel Mailing List
    • The Kernel Bug Tracker
  • Being a Moron on linux-kernel: a guide on how not to behave on the Linux Kernel (or any other) mailing list. (Our recommendation: lurk for at least six-months before posting anything.)

Developing Kernel Modules

Before jumping into core development on the Linux kernel, a good way to increase your knowledge and expertise with Linux programming is to work on a kernel module. These are independently developed pieces of software that work with the kernel in order to function as a complete operating system. Kernel modules include things like device drivers for various hardware peripheries, as well as file managers and other low level operating system features.

The barriers to entry for working on a kernel module are, generally speaking, much lower than they are for working on the Linux kernel. There are hundreds of modules, developed by many different teams and individuals, so there is not one set of gatekeepers setting the tone for development. Moreover, the stakes are a bit lower with module development.

What You Need to Know

Kernel modules, like the kernel itself, are usually written in C. (There is some fringe debate about developing kernel modules in C++, and there are some off-the-wall ways of accomplishing this, but it is certainly not the normal way nor is it recommended.)

Obviously, if you are writing a device driver for a piece of hardware, you will need to know quite a bit about the type of hardware, and the firmware embedded on it. You also need a decent understanding of the Linux-based kernel, and the way that it interacts with kernel modules. Finally, if you are contributing to an existing kernel module, you will need to learn about their procedures and development cycle.

Also see the list of resources above in the Kernel Development section.

We think the following plans will suit the majority of our visitor’s needs.

BlueHost

Dreamhost

SiteGround

A2 Hosting

GreenGeeks

Hostinger

Developing Applications For the Linux Operating System

Once we get up out of the weeds of operating system development, and start talking about developing actual applications for the Linux operating system, the job gets a little easier and we have a lot more options about how to proceed. Compilers and interpreters for just about every programming language are available for the Linux platform, often more than one for a particular language.

What You Need to Know

If you are used to developing for Windows or Mac OS, the biggest shock when developing for Linux is probably the wide variety of Linux environments. There are dozens of Linux distros, and every Linux user has the ability to change quite a lot about how their particular environment works. This means, among other things, that you have to pay attention to dependency management a lot more than you might otherwise need to.

Another difference, particularly as compared to a Windows system is that many Linux users prefer to compile their applications from source code. This happens on Mac OS as well but with less frequency. In the Linux world, a large number of users will always prefer to compile applications from source, rather than using an installer package. This might affect how you think about development and distribution of your software.

Читайте также:  Windows update minitool rsload

Most Linux-centric development takes place in C, C++, Perl, or Python. Learning those languages well, and diving into the resources mentioned above (Kernel and Modules) and below (scripting) will help a lot.

  • C Programming in Linux: a thorough introduction and tutorial about programming Linux applications in the C language.
  • Linux Developer Training: paid courses on Linux development, from the Linux Foundation.

Scripting in Linux

Perhaps the “lowest-level” of programming in Linux is shell scripting. However, this is no less “programming” than anything else. Shell scripting in Linux is a great way to automate routine tasks and accomplish more work in less time. Additionally, digging into advanced shell scripting will give you a deeper knowledge and understanding of the Linux operating system. Shell scripting is really what separates novice Linux consumers from advanced Linux users.

What You Need to Know

While there are other options, the most common scripting language is Bash. Even if you plan to move on to more advanced scripting languages, getting a handle on Bash will start you off on the right foot for all types of operating system scripting. Most people who really get into scripting as a way to boost productivity, use either Python or Perl for most of their work. Once you have hit a wall with what you can easily accomplish in Bash, you will probably want to move onto one of those languages.

Bash Resources

Python Resources

  • Learn Python the Hard Way: one of the most popular introductions to Python development.
  • Automate the Boring Stuff with Python: Practical Programming for Total Beginners: a great introduction to scripting (as opposed to “development”) in Python. Also available for free online as a video course.

Perl Resources

Need Web Hosting?

If you’re in the market for a new web hosting provider, be sure to check out our user reviews, our A-Z hosting guide and our top three popular hosting picks:

General Linux Resources

Linux.org: a central forum for all things Linux.

The Linux Documentation Project: a giant library of Linux guides on all of the subjects above, plus a bunch of other things. This is one of the most important places to go for in-depth Linux information.

Summary

That was a wild ride! From Linux kernel programming all the way down to shell scripting. There are endless ways to program the Linux operating system. With this guide, you should be well on your way.

Источник

C Programming Examples on Linux for Beginners

pre-requisites

You will require a code editor and essential packages to execute C programs. The necessary packages are installed by default on most of the Linux distribution. You can run the following command to check the necessary package is installed or not. The command will display the installed version of gcc.

Example-1: Write and run your first C program

Write the following code using any text editor and save the file with the extension ‘.c’. The header file, stdio.h contains all necessary functions for standard input and output. Any source code of C program starts compilation from the main() method. printf() function is used here to print output in the terminal.

Run the following command to compile and execute the code. The source file name is first.c and executable filename is first_program here.

Example-2: Read user input

scanf() function is used in C to read input from the user which is under stdio.h. C language is a strongly typed language and it supports different data types. Integer and char data type are used in this example. A character array of 100 characters is declared by name variable and an integer is declared by age variable. After taking two inputs from the user the formatted values will be printed by prinf() function.

Читайте также:  Стандартные заставки для рабочего стола windows

Example-3: Read command-line arguments

argc and argv variables are used as parameters in main() method to read command-line argument values. argc is used to read the total number of arguments and argv is used to read the argument values as an array. How to print total number of command-line arguments and first three argument values are shown in this example.

Example-4: Compare string using conditional statements

strcmp() function is used in C language to compare two strings. If two strings are equal then it returns 0. If the first string is larger than the second string then it returns 1. If the first string is less than the second string then it returns -1. In this example, two numeric values and a string value will be taken as input from the user. If the string value is add then it will print the summation of two numbers. If the string value is sub then it will print the subtraction of two numbers. If both if conditions return false then it will print 0.

Example-5: Iterate a list of string using for loop

Array variable is declared by using [] in C program. A list of two dimensional character array is declared in this example that contains 5 string values. sizeof() function is used to count the total number of elements of any array in C. for loop is used in this example to iterate the flowers array and print each element value of the flowers array.

Example-6: Find even numbers from a list using while loop

One dimensional array of 10 integer numbers is declared in this example. The of while loop in C language it shown here. The following code will find out all even numbers from numeric array. If the numbers which are divisible by 2 are even numbers. while loop is used here to read each element of the array and check the remainder value after dividing the element by 2. When the remainder value returns 0 for any element then it will be printed.

Example-7: Find out the area of a rectangle using the function

Each function in C contains return type, function name and the parameters. Parameter-less function can also be declared in C. If any function without main() function is declared in the source code then the prototype of that function must be declared before the function declaration. In this example, area() function is declared to calculate the area of any rectangle that contains two parameters to get the height and width values of the rectangle. main() function will read the height and width value from the user and call area() function to calculate and print the area. The prototype of the area() function is declared at the beginning of the code.

#include
int area ( int h , int w ) ;
int area ( int h , int w )
<
int area = h * w ;
return area ;
>

int main ( )
<
int height , width ;
printf ( «Enter the height of the rectangle:» ) ;
scanf ( «%d» , & height ) ;
printf ( «Enter the width of the rectangle:» ) ;
scanf ( «%d» , & width ) ;

printf ( «The area of the rectangle = %d \n » , area ( height , width ) ) ;
>

Try yourself:

  • Write a C program to take a number as age value of a person and print the person is a teenager or young or old.
  • Write a C program to find out a particular string in a list.
  • Write a C Program using the function to calculate the area of trapezium.

Conclusion:

The most basic parts of programming are described here using simple examples to start programming with C language. The declarations of different variables, conditional statements, loop and function in C are shown in this article.

About the author

Eftakhar

I am a freelancer and blog writer. I love to write article on any computer basic and programming related topics.

Источник

Оцените статью