how to do linux programming in windows and how to start linux programming. what is advanced linux programming. linux programming lecture notes pdf free download
BellaLloyd Profile Pic
Published Date:12-07-2017
Your Website URL(Optional)
LECTURE NOTES ON LINUX PROGRAMMING III B. Tech I semester (JNTUH-R13) Mr. A Krishna Chaitanya, Associate Professor INFORMATION TECHNOLOGY INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS) DUNDIGAL, HYDERABAD - 500 043 1 Syllabus UNIT-I: Linux Utilities-File handling utilities, Security by file permissions, Process utilities, Disk utilities, Networking commands, Filters, Text processing utilities and Backup utilities.sed – scripts, operation, addresses, commands, awk – execution, fields and records.scripts, operation, patterns, actions, associative arrays, string & mathematical functions, system commandsinawk,applications. Shell programming with Bourne again shell(bash): Introduction, shell responsibilities, pipes and Redirection, here documents, running a shell script, the shell as a programming language, shell meta characters, file name substitution, shell variables, command substitution, shell commands, the environment, quoting, test command, control structures, arithmetic in shell, shell script examples, interrupt processing, functions, debugging shell scripts. UNIT-II: Files and Directories: File Concept, File types, File System Structure, File metadata- Inodes, kernel support for files, System calls for file I/O operations- open, create, read, write, close, lseek,dup2, file status information- stat family, file and record locking- fcntl function, file permission- chmod, fchmod, file ownership- chown, lchown, fchown, links- soft links & hard links- symlink, link, ulink Directories: creating, removing and changing directories- mkdir, rmdir, chdir, obtaining current working directory- getcwd, directory contents, scanning directories- opendir, readdir, closedir,rewind dir functions. UNIT-III: Process – Process concept, Layout of a C program, image in main memory, process environment- environment list, environment variables, getenv, setenv, Kernel support for process, process identification, process control - process creation, replacing a process image, waiting for a process, process termination, zombie process, orphan process, system call interface for process management- fork, vfork, exit, wait, waitpid, exec family, process groups, sessions & controlling terminal, differences between threads & processes. Signals– Introduction to signals, Signal generation and handling, Kernel support for signals, 2 Signal function, unreliable signals, reliable signals, kill, raise , alarm, pause, abort, sleep functions. UNIT-IV: Interprocess Communication : Introduction to IPC, IPC between processes on a single computer system, IPC between processes on different systems, Pipes- creation, IPC between related processes using unnamed pipes, FIFOs- creation, IPC between unrelated processes using FIFOs(named pipes), differences between unnamed and named pipes, popen & pclose library functions.Message Queues- Kernel support for messages, APIs for message queues, client/server example. Semaphores-Kernel support for semaphores, APIs for semaphores, file locking with Semaphores UNIT -V: Shared Memory- Kernel support for shared memory, APIs for shared memory, shared memory example.Sockets: Introduction to Berkeley Sockets, IPC over a network, client/server model, Socket Address structures (UNIX domain & internet domain), Socket system calls for connection oriented protocol and connectionless protocol, example-client/server programs- single client/server connection, Multiple simultaneous clients, Socket options- setsockopt & fcntl system calls, comparision of IPC mechanisms. TEXT BOOKS: 1. Unix System Programming using C++, T.Chan, PHI. 2. Unix Concepts and Applications, 4th Edition, Sumitabha Das, TMH. 3. Unix Network Programming, W.R.Stevens,PHI. REFERENCE BOOKS: 1. Beginning Linux Programming, 4th Edition, N.Matthew, R.Stones,Wrox, Wiley India Edition. 2. Unix for programmers and users, 3rd Edition, Graham Glass, King Ables, Pearson Education. 3.System Programming with c and unix,A.Hoover,Pearson. 4. Unix System programming,Communication,Concurrency and Threads,K.A.Robbins and S.Robbins,Pearson Education. 3 rd 5. Unix shell Programming,S.G.kocham and P.Wood,3 edition,Pearson Education. 6.Shell scripting,S.Parker,Wiley India pvt.Ltd. 7. Advanced Programming in the Unix environment, 2nd Edition, W.R.Stevens, Pearson Education. 8. Unix and shell Programming, B.A.Forouzan and R.F.Gilberg,cengage Learning. 9. Linux System Programming,Robert Love,O’Reilly,SPD. 10. C Programming Language,Kernighan and Ritchie,PHI. 4 CONTENTS UNIT : I I.Introduction to Linux 1.Linux Utilities 1.1 File handling utilities 1.2 Security by file permissions 1.3 Process utilities 1.3.1 Disk utilities 1.4 Networking commands 1.4.1 Filters 1.5 Text processing utilities and Backup utilities 1.6 sed, scripts operation addresses commands 1.7 awk – execution, fields and records 1.8 scripts, operation 1.8.1 patterns 1.8.2 actions 1.8.3 Associative arrays 1.8.4 string & mathematical functions 1.8.5 system commands in awk, applications. 1.9 Shell programming with Bourne again shell(bash) 1.9.1 Introduction 1.9.2 shell responsibilitie s 1.10 Pipes and Redirection Here Documents 5 1.11 Running A Shell Script 1.12 The Shell As A Programming Language 1.13 Shell Meta Characters 1.14 File Name Substitution 1.15 Shell Variables 1.16 Command Substitution 1.17 Shell Commands 1.18 The Environment 1.19 Quoting 1.20 Test Command 1.21 Control Structures 1.22 Arithmetic In Shell 1.23 Shell Script Examples 1.24 Interrupt Processing 1.25 Functions 1.26 Debugging Shell Scripts. 6 UNIT-I LINUX UTILITIES AND SHELL PROGRAMMING I. Introduction to Linux: Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of Linux is the Linux kernel, an operating system kernel first released 5 October 1991 by Linus Torvalds. Linux was originally developed as a free operating system for Intel x86-based personal computers. It has since been ported to more computer hardware platforms than any other operating system. It is a leading operating system on servers and other big iron systems such as mainframe computers and supercomputers more than 90% of today's 500 fastest supercomputers run some variant of Linux, including the 10 fastest. Linux also runs on embedded systems (devices where the operating system is typically built into the firmware and highly tailored to the system) such as mobile phones, tablet computers, network routers, televisions and video game consoles; the Android system in wide use on mobile devices is built on the Linux kernel. Basic Features Following are some of the important features of Linux Operating System.  Portable - Portability means softwares can works on different types of hardwares in same way. Linux kernel and application programs supports their installation on any kind of hardware platform.  Open Source - Linux source code is freely available and it is community based development project. Multiple teams works in collaboration to enhance the capability of Linux operating system and it is continuously evolving.  Multi-User - Linux is a multiuser system means multiple users can access system resources like memory/ ram/ application programs at same time.  Multiprogramming - Linux is a multiprogramming system means multiple applications can run at same time.  Hierarchical File System - Linux provides a standard file structure in which system 7 files/ user files are arranged.  Shell - Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs etc.  Security - Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data. Linux Advantages 1.Low cost: You don’t need to spend time and money to obtain licenses since Linux andmuch of its software come with the GNU General Public License. You can start to workimmediately without worrying that your software may stop working anytime because thefree trial version expires. Additionally, there are large repositories from which you canfreely download high quality software for almost any task you can think of. 2.Stability: Linux doesn’t need to be rebooted periodically to maintain performance levels. Itdoesn’t freeze up or slow down over time due to memory leaks and such. Continuous up- times of hundreds of days (up to a year or more) are not uncommon. 3.Performance: Linux provides persistent high performance on workstations and onnetworks. It can handle unusually large numbers of users simultaneously, and can make oldcomputers sufficiently responsive to be useful again. 4.Network friendliness: Linux was developed by a group of programmers over the Internet and has therefore strong support for network functionality; client and server systems can be easily set up on any computer running Linux. It can perform tasks such as network backups faster and more reliably than alternative systems. 5.Flexibility: Linux can be used for high performance server applications, desktop applications, and embedded systems. You can save disk space by only installing the components needed for a particular use. You can restrict the use of specific computers by installing for example only selected office applications instead of the whole suite. 6.Compatibility: It runs all common Unix software packages and can process all common file formats. 7.Choice: The large number of Linux distributions gives you a choice. Each distribution is developed and supported by a different organization. You can pick the one you like best; the 8 core functionalities are the same; most software runs on most distributions. 8.Fast and easy installation: Most Linux distributions come with user-friendly installation and setup programs. Popular Linux distributions come with tools that make installation of additional software very user friendly as well. 9.Full use of hard disk: Linux continues work well even when the hard disk is almost full. 10.Multitasking: Linux is designed to do many things at the same time; e.g., a large printing job in the background won’t slow down your other work. 11.Security: Linux is one of the most secure operating systems. “Walls” and flexible file access permission systems prevent access by unwanted visitors or viruses. Linux users have to option to select and safely download software, free of charge, from online repositories containing thousands of high quality packages. No purchase transactions requiring credit card numbers or other sensitive personal information are necessary. 12.Open Source: If you develop software that requires knowledge or modification of the operating system code, Linux’s source code is at your fingertips. Most Linux applications are Open Source as well. Difference between UNIX and LINUX Features LINUX UNIX Cost Linux can be freely distributed, Different flavors of Unix have downloaded freely, distributed different cost structures according through magazines, Books etc. to vendors There are priced versions for Linux also, but they are normally cheaper than Windows. Development Linux is developed by Open Unix systems are divided into and Source development i.e. through various other flavors, mostly Distribution sharing and collaboration of developed by AT&T as well as code and features through various commercial vendors and forums etc and it is distributed non-profit organizations. 9 by various vendors. Manufacturer Linux kernel is developed by Three bigest distributions are the community. Linus Torvalds Solaris (Oracle), AIX (IBM) & HP- oversees things. UX Hewlett Packard. And Apple Makes OSX, an unix based os.. User Everyone. From home users to Unix operating systems were developers and computer developed mainly for mainframes, enthusiasts alike. servers and workstations except OSX, Which is designed for everyone. The Unix environment and the client-server program model were essential elements in the development of the Internet Usage Linux can be installed on a wide The UNIX operating system is used variety of computer hardware, in internet servers, workstations & ranging from mobile phones, PCs. Backbone of the majority of tablet computers and video finance infastructure and many game consoles, to mainframes 24x365 high availability solutions. and supercomputers. File system Ext2, Ext3, Ext4, Jfs, ReiserFS, jfs, gpfs, hfs, hfs+, ufs, xfs, zfs Xfs, Btrfs, FAT, FAT32, NTFS format support Text mode BASH (Bourne Again SHell) is Originally the Bourne Shell. Now interface the Linux default shell. It can it's compatible with many others support multiple command including BASH, Korn & C. interpreters. Linux is an example of Open Unix is an operating system that is What is it? Source software development very popular in universities, and Free Operating System companies, big enterprises etc. (OS). 10 GUI Linux typically provides two Initially Unix was a command GUIs, KDE and Gnome. But based OS, but later a GUI was there are millions of alternatives created called Common Desktop such as LXDE, Xfce, Unity, Environment. Most distributions Mate, twm, ect. now ship with Gnome. Free but support is available for Some free for development use Price a price. (Solaris) but support is available for a price. Linux has had about 60-100 A rough estimate of UNIX viruses Security viruses listed till date. None of is between 85 -120 viruses reported them actively spreading till date. nowadays. Threat In case of Linux, threat Because of the proprietary nature of detection and detection and solution is very the original Unix, users have to fast, as Linux is mainly wait for a while, to get the proper solution community driven and bug fixing patch. But these are not whenever any Linux user posts as common. any kind of threat, several developers start working on it from different parts of the world Dozens of different kinds. x86/x64, Sparc, Power, Itanium, Processors PA-RISC, PowerPC and many others. Examples Ubuntu, Fedora, Red Hat, OS X, Solaris, All Linux Debian, Archlinux, Android etc. Originally developed for Intel's is available on PA-RISC and Architectures x86 hardware, ports available Itanium machines. Solaris also for over two dozen CPU types available for x86/x64 based including ARM systems.OSX is PowerPC(10.0- 11 10.5)/x86(10.4)/x64(10.5-10.8) Inception Inspired by MINIX (a Unix-like In 1969, it was developed by a system) and eventually after group of AT&T employees at Bell adding many features of GUI, Labs and Dennis Ritchie. It was Drivers etc, Linus Torvalds written in “C” language and was developed the framework of the designed to be a portable, multi- OS that became LINUX in tasking and multi-user system in a 1992. The LINUX kernel was time-sharing configuration released on 17th September, 1991 Linux Distribution (Operating System) Names A few popular names: 1.Redhat Enterprise Linux 2.Fedora Linux 3.Debian Linux 4.Suse Enterprise Linux 5.Ubuntu Linux Common Things Between Linux & UNIX Both share many common applications such as: 1.GUI, file, and windows managers (KDE, Gnome) 2.Shells (ksh, csh, bash) 3.Various office applications such as OpenOffice.org 12 4.Development tools (perl, php, python, GNU c/c++ compilers) 5.Posix interface Layered Architecture: Linux System Architecture is consists of following layers  Hardware layer - Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).  Kernel - Core component of Operating System, interacts directly with hardware, provides low level services to upper layer components.  Shell - An interface to kernel, hiding complexity of kernel's functions from users. Takes commands from user and executes kernel's functions.  Utilities - Utility programs giving user most of the functionalities of an operating systems. LINUX File system Linux file structure files are grouped according to purpose. Ex: commands, data files, documentation. Parts of a Unix directory tree are listed below. All directories are grouped under the root entry "/". That part of the directory tree is left out of the below diagram. 13 1. / – Root  Every single file and directory starts from the root directory.  Only root user has write privilege under this directory.  Please note that /root is root user’s home directory, which is not same as /. 2. /bin – User Binaries  Contains binary executables.  Common linux commands you need to use in single-user modes are located under this directory.  Commands used by all the users of the system are located here.  For example: ps, ls, ping, grep, cp. 3. /sbin – System Binaries  Just like /bin, /sbin also contains binary executables.  But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.  For example: iptables, reboot, fdisk, ifconfig, swapon 4. /etc – Configuration Files 14  Contains configuration files required by all programs.  This also contains startup and shutdown shell scripts used to start/stop individual programs.  For example: /etc/resolv.conf, /etc/logrotate.conf 5. /dev – Device Files  Contains device files.  These include terminal devices, usb, or any device attached to the system.  For example: /dev/tty1, /dev/usbmon0 6. /proc – Process Information  Contains information about system process.  This is a pseudo filesystem contains information about running process. For example: /proc/pid directory contains information about the process with that particular pid.  This is a virtual filesystem with text information about system resources. For example: /proc/uptime 7. /var – Variable Files  var stands for variable files.  Content of the files that are expected to grow can be found under this directory.  This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp); 8. /tmp – Temporary Files  Directory that contains temporary files created by system and users.  Files under this directory are deleted when system is rebooted. 9. /usr – User Programs  Contains binaries, libraries, documentation, and source-code for second level programs.  /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp  /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel  /usr/lib contains libraries for /usr/bin and /usr/sbin  /usr/local contains users programs that you install from source. For example, when you 15 install apache from source, it goes under /usr/local/apache2 10. /home – Home Directories  Home directories for all users to store their personal files.  For example: /home/john, /home/nikita 11. /boot – Boot Loader Files  Contains boot loader related files.  Kernel initrd, vmlinux, grub files are located under /boot  For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic 12. /lib – System Libraries  Contains library files that supports the binaries located under /bin and /sbin  Library filenames are either ld or lib.so.  For example: ld-2.11.1.so, libncurses.so.5.7 13. /opt – Optional add-on Applications  opt stands for optional.  Contains add-on applications from individual vendors.  add-on applications should be installed under either /opt/ or /opt/ sub-directory. 14. /mnt – Mount Directory  Temporary mount directory where sysadmins can mount filesystems. 15. /media – Removable Media Devices  Temporary mount directory for removable devices.  For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer 16. /srv – Service Data  srv stands for service.  Contains server specific services related data.  For example, /srv/cvs contains CVS related data. 1. Linux Utilities: 1.1 File Handling utilities: Cat 16 Command: cat linux command concatenates files and print it on the standard output. SYNTAX: The Syntax is cat OPTIONS FILE... OPTIONS: -A Show all. -b Omits line numbers for blank space in the output. -e A character will be printed at the end of each line prior to a new line. -E Displays a (dollar sign) at the end of each line. -n Line numbers for all the output lines. -s If the output has multiple empty lines it replaces it with one empty line. -T Displays the tab characters in the output. Non-printing characters (with the exception of tabs, new-lines and form-feeds) -v are printed visibly. Example: To Create a new file: cat file1.txt This command creates a new file file1.txt. After typing into the file press control+d (d) simultaneously to end the file. 1. To Append data into the file: cat file1.txt To append data into the same file use append operator to write into the file, else the file will be overwritten (i.e., all of its contents will be erased). 2. To display a 17 file: cat file1.txt This command displays the data in the file. 3. To concatenate several files and display: cat file1.txt file2.txt 18 The above cat command will concatenate the two files (file1.txt and file2.txt) and it will display the output in the screen. Some times the output may not fit the monitor screen. In such situation you can print those files in a new file or display the file using less command. cat file1.txt file2.txt less 4. To concatenate several files and to transfer the output to another file. cat file1.txt file2.txt file3.txt In the above example the output is redirected to new file file3.txt. The cat command will create new file file3.txt and store the concatenated output into file3.txt. rm COMMAND: rm linux command is used to remove/delete the file from the directory. SYNTAX: The Syntax is rm options.. file directory OPTIONS: -f Remove all files in a directory without prompting the user. Interactive. With this option, rm prompts for confirmation before removing -i any files. Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally -r (or) -R prompted for removal of any write-protected files which the directory contains. EXAMPLE: 19 1. To Remove / Delete a file: rm file1.txt Here rm command will remove/delete the file file1.txt. 2. To delete a directory tree: rm -ir tmp This rm command recursively removes the contents of all subdirectories of the tmp directory, prompting you regarding the removal of each file, and then removes the tmp directory itself. 3. To remove more files at once rm file1.txt file2.txt rm command removes file1.txt and file2.txt files at the same time. cd COMMAND: cd command is used to change the directory. SYNTAX: The Syntax is cd directory ./ ../ - OPTIONS: -L Use the physical directory structure. -P Forces symbolic links. EXAMPLE: 1. cd linux-command This command will take you to the sub-directory(linux-command) from its parent directory. 20

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.