Hi All,
I am new to this group. I am not sure whether this is the right place to ask this kind
of question. Here is my doubt.
I wrote a simple C program.
#include<stdio.h>
#include<unistd.h>
int main()
{
printf("Hello, World\n");
sleep(10);
}
if i compile this program using "gcc sample.c -o sample" and run this using 'strace',
case 1) run as fg process using "strace ./sample" in command prompt
write(1, "Hello, World\n", 13Hello, World) = 13
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, {10, 0}) = 0
case 2 ) run the above command with making this bg process (attaching &)
#strace ./sample &
same output
case 3) running the above command inside a shell script
tesh.sh
strace ./sample 2>&1 |tee my.log
if i run the shell script in command prompt using #./test.sh, i am getting this output :
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, {10, 0}) = 0
write(1, "Hello, World\n", 13Hello, World ) = 13
here the sequence is different :- first sleep()[nanosleep()] and then write().
it looks surprising for me why the sequence is differet here. could anybody please clarify me ?
Thanks a lot in advance :)
regards/santosh