## vfork ##
建立一個新的進程
### 相關函數 ###
wait,execve
### 表頭文件 ###
```
#include<unistd.h>
```
### 定義函數 ###
```
pid_t vfork(void);
```
### 函數說明 ###
vfork()會產生一個新的子進程,其子進程會復制父進程的數據與堆棧空間,并繼承父進程的用戶代碼,組代碼,環境變量、已打開的文件代碼、工作目錄和資源限制等。Linux 使用copy-on-write(COW)技術,只有當其中一進程試圖修改欲復制的空間時才會做真正的復制動作,由于這些繼承的信息是復制而來,并非指相同的內存空間,因此子進程對這些變量的修改和父進程并不會同步。此外,子進程不會繼承父進程的文件鎖定和未處理的信號。注意,Linux不保證子進程會比父進程先執行或晚執行,因此編寫程序時要留意
死鎖或競爭條件的發生。
### 返回值 ###
如果vfork()成功則在父進程會返回新建立的子進程代碼(PID),而在新建立的子進程中則返回0。如果vfork 失敗則直接返回-1,失敗原因存于errno中。
### 錯誤代碼 ###
EAGAIN 內存不足。ENOMEM 內存不足,無法配置核心所需的數據結構空間。
### 范例 ###
```
#include<unistd.h>
main()
{
if(vfork() = =0)
{
printf(“This is the child process\n”);
}else{
printf(“This is the parent process\n”);
}
}
```
### 執行 ###
```
this is the parent process
this is the child process
```
- 字符測試篇
- isalnum
- isalpha
- isascii
- iscntrl
- isdigit
- isgraphis
- islower
- isprint
- isspace
- ispunct
- isupper
- isxdigit
- 字符串轉換篇
- atof
- atoi
- atol
- gcvt
- strtod
- strtol
- strtoul
- toascii
- tolower
- toupper
- 內存控制篇
- calloc
- free
- getpagesize
- malloc
- mmap
- munmap
- 日期時間篇
- asctime
- ctime
- gettimeofday
- gmtime
- localtime
- mktime
- settimeofday
- time
- 內存及字符串操作篇
- bcmp
- bcopy
- bzero
- index
- memccpy
- memchr
- memcmp
- memcpy
- memmove
- memset
- rindex
- strcasecmp
- strcat
- strchr
- strcmp
- strcoll
- strcpy
- strcspn
- strdup
- strlen
- strncasecmp
- strncat
- strncpy
- strpbrk
- strrchr
- strspn
- strstr
- strtok
- 常用數學函數篇
- abs
- acos
- asin
- atan
- atan2
- ceil
- cos
- cosh
- exp
- frexp
- ldexp
- log
- log10
- pow
- sin
- sinh
- sqrt
- tan
- tanh
- 用戶組篇
- endgrent
- endpwent
- endutent
- fgetgrent
- fgetpwent
- getegid
- geteuid
- getgid
- getgrent
- getgrgid
- getgrnam
- getgroups
- getpw
- getpwent
- getpwnam
- getpwuid
- getuid
- getutent
- getutid
- getutline
- initgroups
- pututline
- seteuid
- setfsgid
- setfsuid
- setgid
- setgrent
- setgroups
- setpwent
- setregid
- setreuid
- setuid
- setutent
- utmpname
- 數據結構及算法篇
- crypt
- bsearch
- lfind
- lsearch
- qsort
- rand
- srand
- 文件操作篇
- close
- creat
- dup
- dup2
- fcntl
- flock
- fsync
- lseek
- mkstemp
- open
- read
- sync
- write
- 文件內容操作篇
- clearerr
- fclose
- fdopen
- feof
- fflush
- fgetc
- fgets
- fileno
- fopen
- fputc
- fputs
- fread
- freopen
- fseek
- ftell
- fwrite
- getc
- getchar
- gets
- mktemp
- putc
- putchar
- rewind
- setbuf
- setbuffer
- setlinebuf
- setvbuf
- ungetc
- 進程操作篇
- atexit
- execl
- execlp
- execv
- execve
- execvp
- exit
- _exit
- vfork
- getpgid
- getpgrp
- getpid
- getppid
- getpriority
- nice
- on_exit
- setpgid
- setpgrp
- setpriority
- system
- wait
- waitpid
- 格式化輸入輸出篇
- fprintf
- fscanf
- printf
- scanf
- sprintf
- sscanf
- vfprintf
- vfscanf
- vprintf
- vscanf
- vsprintf
- vsscanf
- 文件權限控制篇
- access
- alphasort
- chdir
- chmod
- chown
- chroot
- closedir
- fchdir
- fchmod
- fchown
- fstat
- ftruncate
- getcwd
- link
- lstat
- opendir
- readdir
- readlink
- remove
- rename
- rewinddir
- seekdir
- stat
- symlink
- telldir
- truncate
- umask
- unlink
- utime
- utimes
- 信號處理篇
- alarm
- kill
- pause
- sigaction
- sigaddset
- sigdelset
- sigemptyset
- sigfillset
- sigismember
- signal
- sigpending
- sigprocmask
- sleep
- ferror
- perror
- strerror
- mkfifo
- pclose
- pipe
- popen
- 接口處理篇
- accept
- bind
- connect
- endprotoent
- endservent
- getsockopt
- htonl
- htons
- inet_addr
- inet_aton
- inet_ntoa
- listen
- ntohl
- ntohs
- recv
- recvfrom
- recvmsg
- send
- sendmsg
- sendto
- setprotoent
- setservent
- setsockopt
- shutdown
- socket
- 環境變量篇
- getenv
- putenv
- setenv
- 終端控制篇
- getopt
- isatty
- select
- ttyname