3

I'm doing some work on pipes and forks. I have this strace output, however i am unsure why clone is used and not fork. Does this mean they are the same?

Strace output

enter codexecve("./forks", ["./forks"], [/* 55 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x7f2b0e498700) = 0
pipe([3, 4])                            = 0
clone(Process 7304 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f2b0e4989d0) = 7304
[pid  7303] execve("/usr/bin/wc", ["wc", "-l"], [/* 55 vars */] <unfinished ...>
[pid  7304] execve("/bin/ls", ["ls"], [/* 55 vars */] <unfinished ...>
[pid  7303] <... execve resumed> )      = 0
[pid  7304] <... execve resumed> )      = 0
[pid  7303] arch_prctl(ARCH_SET_FS, 0x7f558acde700) = 0
[pid  7304] arch_prctl(ARCH_SET_FS, 0x7f4bef4f67c0) = 0
[pid  7304] exit_group(0)               = ?
Process 7304 detached
--- SIGCHLD (Child exited) @ 0 (0) ---
21
exit_group(0) 
chrk
  • 4,037
  • 2
  • 39
  • 47

1 Answers1

5

No, fork() and clone() aren't the same. However, you can imagine both of them as functions used as wrappers around clone() syscall, meaning that they use the same clone() syscall internally to create the new process. That explains what you observed on strace's output.

Check this and this question; they explain the differences better than I could.

Community
  • 1
  • 1
chrk
  • 4,037
  • 2
  • 39
  • 47