Linux Programming Basics

Source: Internet
Author: User

Use of libraries
Header file:. h declarations of functions and variables such as # include <stdio.h>, the search path of the default header file under Linux
System-Defined header files:
/usr/include
/usr/local/include
/usr/target/include (different paths for different platforms)
Library files:/lib64
C Library functions

[Email protected] c]# ls/lib64/libc.so.6
/lib64/libc.so.6

See which libraries are used by a program
ldd Executable Path

//wait.c Code#include <sys/wait.h>#include<sys/types.h>#include<unistd.h>#include<stdio.h>#include<stdlib.h>voidChildintdelay)    {Sleep (delay); Exit (0);}voidParentint*status) {Wait (status);}    Main () {pid_t pid; intstatus; printf ("before:%d\n", Getpid ()); PID=Fork (); if(PID = =0) {Child (Ten); }    if(PID >0) {printf ("PID =%d\n", Getpid ()); Parent (&status); printf ("Status =%d\n", status); }}

[Email protected] c]# LDD./wait
Linux-vdso.so.1 = (0x00007ffebd1d2000)
libc.so.6 =/lib64/libc.so.6 (0x000000333a200000)
/lib64/ld-linux-x86-64.so.2 (0x0000003339e00000)

Compile-time default link C library, if you use other libraries compiled with-l
For example, using a math library
Gcc-o M.C-LM-LC

System Limitations
The type of platform itself: 32-bit, 64-bit
Limitations of data types:
Position according to the machine
/usr/include/limits.h
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/include/float.h
Limitations of the system itself
Command line: Ulimit to modify and retrieve
To use when programming:
Getrlimit to get

Setrlimit to set

Mans Getrlimit#include<sys/time.h>#include<sys/resource.h>intGetrlimit (intResourcestructRlimit *Rlim);intSetrlimit (intResourceConst structRlimit *Rlim);structrlimit {rlim_t rlim_cur; /*Soft Limit*/rlim_t Rlim_max; /*Hard limit (ceiling for rlim_cur)*/       }; resource Some values rlimit_core:core the maximum number of bytes for a file. The CORE file is the context information that the system saves for the system when an exception exits, and the rlimit_cpu:cpu time maximum (in seconds) is often required for GDB debugging. Rlimit_data: Maximum number of bytes in a process data segment rlimit_fsize: The maximum size of a file can be created Rlimit_nofile: The number of files that each process can open Rlimit_stack: The maximum value of the process stack space, Make the system not automatically dynamically modify this limit Rlimit_vmem: Maximum value of virtual address space rlimit_as: System process free memory space maximum 

Linux Programming Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.