LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   fork() (https://www.linuxquestions.org/questions/linux-software-2/fork-185087/)

vibhory2j 05-24-2004 02:08 AM

fork()
 
hi,
i am new to linux. i just to want to know that if a command like fork() exists in Linux and if yes please tell me the use of it.

Thanks...

cheers

bahramH 05-24-2004 04:11 AM

fork ? Of course
 
Yes, of course fork exists in linux/C, and is similar to what it does in UNIX.

All these linux/unixes are multiprocesses operating systems, which means that at any given time, you have multiple process running in parallel (windows does the same since I guess
windows 98). ( ps -ef gives you all the running processes)

You have the ability, inside one process, to launch a new one. Each living process has a unique ID number (called PID) and a number referring to its parent ID (called PPID), i.e. the process which launched this one.

when you use the fork() command, you duplicate your original process. The processes are similar to each other, exept the PID and PPID. (fork return the pid of the child process)

Now, by cheking inside the two processes their own pid, you can induce each of them to perform a different task. You have many way to synchronize them. Look at the man pages for

fork, waitpid, ptrace,clone, exec, ...

I think the same concept in windows is called multithreading.


All times are GMT -5. The time now is 09:25 PM.