日期:2014-05-16  浏览次数:20783 次

linux中的fork是创建进程还是线程?
linux操作系统中,我认为fork是创建线程,exec之后就是进程了。
而同事说fork是创建进程,pthread是线程。


------解决方案--------------------
NAME
       fork - create a child process

SYNOPSIS
       #include <unistd.h>

       pid_t fork(void);

DESCRIPTION
       fork()  creates a new process by duplicating the calling process.  The new process, referred to as the child, is an exact duplicate
       of the calling process, referred to as the parent, except for the following points:
------解决方案--------------------
man fork
------解决方案--------------------
fork是创建进程,pthread是线程。
------解决方案--------------------
linux程序设计第四版     人民邮电出版社
------解决方案--------------------
是否线程安全要看具体的函数
------解决方案--------------------
引用:
再请教个问题,c库函数是线程安全的吗?socket函数是线程安全的吗?

有的是有的不是
比如
   Multithreading (see pthreads(7))
       The strerror() function is not thread-safe.

       The strerror_r() function is thread-safe.

------解决方案--------------------
fork()函数是用来创建子进程的,,,pthread_create()是用来创建线程的
------解决方案--------------------
pthread_create  也是call  fork 族的函数实现的,so。。。