Hello experts,
I am simply analyzing the clone()
and execve()
cycles for series of commands using strace
.
strace
is run from different terminal using PID of shell to see complete trace.
In the following combination :
bash -c "cat file1; cat file2"
it is observed that :
clone()
called for bash -c
execve ()
called for bash -c
, and this calls clone()
again for cat file1
with execve()
,
no clone()
is called for cat file2
, and is executed with same execve()
of the bash -c
.
Can somebody please explain where, in which space second command is executing , because no child is created, and there exists no sub shell, (and why separate child is not created)
# strace -f -p 299 > stlog 2>&1
^C
# cat stlog | grep -n clone
18:clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLDstrace: Process 1805 attached
285:[pid 1805] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLDstrace: Process 1806 attached
# cat stlog | grep -n execve
90:[pid 1805] execve("/usr/bin/bash", ["bash", "-c", "cat filer1; cat filer2"], 0x5fa26e095730 /* 26 vars */) = 0
313:[pid 1806] execve("/usr/bin/cat", ["cat", "filer1"], 0x6476b8eb6220 /* 26 vars */) = 0
443:[pid 1805] execve("/usr/bin/cat", ["cat", "filer2"], 0x6476b8eb6890 /* 26 vars */) = 0