Common API summary for Linux systems

Source: Internet
Author: User
Tags local time semaphore

1. Error handling

-fprintf ()

-Perror ()

2. General-purpose I/O model

-FD = open (pathname, flags, mode)

-Numread = Read (fd, buffer, count)

-Numwritten = Write (fd, buffer, count)

-Status = Close (FD)

-off_t lseek (int fd, off_t offset, int whence): Change file offset

-INT IOCTL (int fd, int request, .../*argp*/)

-int fcntl (int fd, int cmd, ...) : File Control operations

-int dup (int oldfd): Copy the file descriptor, return the new file descriptor, ensure the file descriptor is minimal

-int dup2 (int oldfd, int newfd): Create a copy for OLDFD, numbered NEWFD

-ssize_t pread (int fd, void *buf, size_t count, off_t offset): Read at offset

-ssize_t pwrite (int fd, const void *buf, size_t count, off_t offset): Write at offset

-ssize_t readv (int fd, const struct IOVEC *iov, int iovcnt): Decentralized input

-ssize_t Writev (int fd, const struct IOVEC *iov, int iovcnt): Centralized output

-Int truncate (const char *pathname, off_t length): File truncation

-int ftruncate (int fd, off_t length)

-Int mkstemp (char *template): The last 6 characters of a template must be xxxxxx, such as char template[] = "/tmp/somestringxxxxxx"

-File *tmpfile (void): Create temporary file

3. Process

-pid_t getpid (void): Returns the process number of the calling process

-pid_t getppid (void): Returns the parent process process number

-pid_t fork (void)

-Void exit (int status)

-pid_t Wait (int *status): Wait for the child process resource to be reclaimed

-pid_t waitpid (pid_t pid, int *status, int options)

-Int Execve (const char *pathname, char *const argv[], char *const envp[])

-INT System (const char *command): Execute arbitrary shell command

4. Memory allocation

-void *malloc (size_t size)

-Void free (void *ptr)

-Void *calloc (size_t numitems, size_t size): Used to allocate memory for a set of identical objects

-void *realloc (void *ptr, size_t size): Used to adjust the size of a block of memory previously allocated by the malloc function

-void *alloca (size_t size): Ability to allocate memory on the stack without manual release

5. Time

-time_t time (time_t *TIMEP)

-Char *ctime (const time_t *TIMEP): Returns a string representation, Wed June 8 14:2:32 2011

-struct TM *gmtime (const time_t *TIMEP): corresponds to UTC green Time decomposition

-struct TM *localtime (const time_t *TIMEP): Corresponding system local time decomposition

-Char *asctime (const struct TM *timeptr): output format same as CTime

-size_t strftime (char *outstr, size_t maxsize, const char *format, const struct TM *timeptr)

-Char *currtime (const char *format): connotation strftime formatting the current time by the format parameter

-Char *strptime (const char *STR, const char *format, struct TM *timeptr): Converts a string containing a date and time to a decomposition time

6. File I/O

-Int setvbuf (FILE *stream, char *buf, int mode, size_t size): Control stdio Library using buffered form

-Int fflush (FILE *stream): Flush stdio Buffer

-int Fsync (int fd): Flushes buffered data and all elements associated with open file descriptor fd to disk

-int Fileno (file *stream): Convert a stream pointer to a file descriptor

-FILE *fdopen (int fd, const char *mode)

-INT stat (const char *pathname, struct stat *statbuf): Returns information about the named file

-Int Lstat (const char *pathname, struct stat *statbuf): Returns information about the connection file itself

-int Fstat (int fd, struct stat *statbuf)

-int Access (const CAHR *pathname, int mode): Check the access rights of the file

-mode_t umask (mode_t mask): Sets the Umake value of the process

-int chmod (const char *pathname, mode_t mode): Change the file permissions specified by the pathname parameter

-int Fchmod (int fd, mode_t mode)

7. Catalogs and Links

-Int link (const char *oldpath, const char *newpath): Create a hard link

-Int unlink (const char *pathname): Remove hard Links

-int rename (const char *oldpath, const char *newpath): You can either rename the file or move the file to another directory on the same file system

-Int symlink (const char *filepath, const char *linkpath): Soft connection

-int mkdir (const char *pathname, mode_t mode): Create a new directory

-Int rmdir (const char *pathname)

-int Remove (const char *pathname)

-DIR *opendir (const char *dirpath)

-DIR *fdopendir (int fd)

-struct dirent *readdir (DIR *dirp)

-Void Rewinddir (DIR *dirp)

-Int Closedir (DIR *dirp)

-Int Dirfd (DIR *dirp): Returns the file descriptor associated with the DIRP directory stream

-Int NFTW (const char *dirpath, INT (*func) const char *pathname, const struct STAT *statbuf, int typeflag, struct FIW *ft WBUF), int nopenfd, int flags): recursively traverse directory

-Char *getcwd (char *cwdbuf, size_t size): Gets the current working directory

-Int chdir (const char *pathname): Changes the current working directory

-int Fchdir (int fd)

8. Signal

-Void (*signal (int sig, void (*handler))) (int): Change signal processing

-int Kill (pid_t pid, int sig): Send Signal

-Int raise (int sig): Sends a signal to itself

-int Pause (void): Suspends the process until a signal is interrupted

-Unsigned int sleep (unsigned int seconds)

-Int Timer_create (clockid_t clockid, struct sigevent *evp, timer_t *timerid): Create timer

-Int Timer_settime (timer_t timerid, int flags, const struct ITIMERSPEC *value, struct itimerspec *old_value): Set timer

-Int Timer_gettimer (timer_t timerid, struct itimerspec *curr_value): Gets the current value of the timer

-Int Timer_delete (timer_t timerid)

9. Threads

-Int Pthread_create (pthread_t *thread, const pthread_attr_t *attr, void * (*start) (void *), void *arg): Create thread

-void Pthread_exit (void *retval): terminating thread

-pthread_t pthread_self (void): Get thread ID

-int pthread_equal (pthread_t t1, pthread_t T2): Check if two thread IDs are the same

-int Pthread_join (pthread_t thread, void **retval): Waits for thread to terminate and returns after end

-int Pthread_detach (pthread_t thread): The thread thread tag is in a detached state, and the system automatically cleans up and removes it when it terminates

-Int Pthread_mutex_lock (pthread_mutex_t *mutex): Lock and Unlock Mutex

-Int Pthread_mutex_unlock (pthread_mutex_t *mutex)

10. Inter-process communication

Pipeline

-INT pipe (int filedes[2]): Create nameless pipe

-Int Mkfifo (const char *pathname, mode_t mode): Creating a named pipe

Message Queuing

-int Msgget (key_t key, int msgflg): Create a new message queue or get an identifier for an existing queue

-int msgsnd (int msqid, const void *MSGP, size_t msgsz, int msgflg): Writes a message to Message Queuing

-ssize_t MSGRCV (int msqid, void *msgp, size_t maxmsgz, long Msgtyp, int msgflg): Read and delete messages from Message Queuing

-int Msgctl (int msqid, int cmd, struct msqid_ds *buf): Performs a control operation on the message queue of the identifier Wiemsqid

Signal Volume

-int Semget (key_t key, int nsems, int semflg): Create a new semaphore set

-int Semctl (int semid, int semnum, int cmd, ...) : Performs various control operations on a semaphore set

Shared memory

-int Shmget (key_t key, size_t size, int shmflg): Create a new Shared memory segment or get an identifier for an existing segment

-void *shmat (int shmid, const void *shmaddr, int shmflg): Shared memory segment identified by Shmid

-int SHMDT (const void *SHMADDR): Use SHMDT to detach when no access to shared memory is required

-int Shmctl (int shmid, int cmd, struct shmid_ds *buf)

File mapping

-void *mmap (void *addr, size_t length, int prot, int flags, int fd, off_t offset): Creates a new mapping in the virtual address space of the calling process

-int Munmap (void *addr, size_t length): de-map area

-int Msync (void *addr, size_t length, int flags): Synchronous map Area

11. Network

Streaming sockets

-int socket (int domain, int type, int protocol): Create a socket

-int bind (int sockfd, const struct SOCKADDR *addr, socklen_t Addrlen): Bind socket to address

-int Listen (int sockfd, int backlog): Listen for access connection

-int Accept (int sockfd, struct sockaddr *addr, socklen_t Addrlen): Accept Connection

-int Connect (int sockfd, const struct SOCKADDR *addr, socklen_t Addrlen): Connect to Peer Socket

-int Close (int fd): Connection terminated

Packet sockets

-ssize_t recvfrom (int sockfd, void *buffer, size_t length, int flags, struct sockaddr *src_addr, socklen_t *addrne)

-ssize_t sendto (int sockfd, const void *buffer, size_t length, int flags, const struct SOCKADDR *dest_addr, socklen_t add Rlen)

Common API summary for Linux systems

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.