Code:
[user@host1: /tmp] cat x.sh
#!/bin/ksh
MyFiles ()
{
grep "<TAG1>" < file1 >> file2
grep "<TAG2>" < file1 >> file2
}
MyFiles;
[user@host1: /tmp] strace ./x.sh > /tmp/x.trace 2>&1
[user@host1: /tmp] cat x.trace
...
stat("/bin/grep", {st_mode=S_IFREG|0755, st_size=88896, ...}) = 0
lstat("/bin/grep", {st_mode=S_IFREG|0755, st_size=88896, ...}) = 0
open("file1", O_RDONLY) = 3
fcntl(0, F_DUPFD, 10) = 11
fcntl(11, F_SETFD, FD_CLOEXEC) = 0
close(0) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff3f5edea0) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=60, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=60, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
fcntl(3, F_DUPFD, 0) = 0
close(3) = 0
close(3) = -1 EBADF (Bad file descriptor)
open("file2", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
fcntl(1, F_DUPFD, 10) = 12
fcntl(12, F_SETFD, FD_CLOEXEC) = 0
close(1) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff3f5edea0) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=38, ...}) = 0
fcntl(3, F_DUPFD, 1) = 1
close(3) = 0
fstat(1, {st_mode=S_IFREG|0644, st_size=38, ...}) = 0
lseek(1, 0, SEEK_CUR) = 0
close(3) = -1 EBADF (Bad file descriptor)
rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT PIPE], [], 8) = 0
vfork() = 6750
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(1) = 0
fcntl(12, F_DUPFD, 1) = 1
close(12) = 0
close(0) = 0
fcntl(11, F_DUPFD, 0) = 0
close(11) = 0
rt_sigaction(SIGINT, {0x416ac0, [], SA_RESTORER|SA_INTERRUPT, 0x385be302d0}, {SIG_DFL, [], 0}, 8) = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WSTOPPED|WCONTINUED, NULL) = 6750
--- SIGCHLD (Child exited) @ 0 (0) ---
rt_sigreturn(0x11) = 6750
wait4(-1, 0x7fff3f5ee494, WNOHANG|WSTOPPED|WCONTINUED, NULL) = -1 ECHILD (No child processes)
wait4(-1, 0x7fff3f5ee494, WNOHANG|WSTOPPED|WCONTINUED, NULL) = -1 ECHILD (No child processes)
rt_sigaction(SIGCHLD, {0x423cf0, [], SA_RESTORER|SA_INTERRUPT, 0x385be302d0}, {0x423cf0, [], SA_RESTORER|SA_INTERRUPT, 0x385be302d0}, 8) = 0
ioctl(2, TIOCGPGRP, [0]) = -1 ENOTTY (Inappropriate ioctl for device)
open("file1", O_RDONLY) = 3
fcntl(0, F_DUPFD, 10) = 11
fcntl(11, F_SETFD, FD_CLOEXEC) = 0
close(0) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff3f5edea0) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=60, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=60, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
fcntl(3, F_DUPFD, 0) = 0
close(3) = 0
close(3) = -1 EBADF (Bad file descriptor)
open("file2", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
fcntl(1, F_DUPFD, 10) = 12
fcntl(12, F_SETFD, FD_CLOEXEC) = 0
close(1) = 0
fcntl(12, F_SETFD, FD_CLOEXEC) = 0
close(1) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff3f5edea0) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=56, ...}) = 0
fcntl(3, F_DUPFD, 1) = 1
close(3) = 0
fstat(1, {st_mode=S_IFREG|0644, st_size=56, ...}) = 0
lseek(1, 0, SEEK_CUR) = 0
close(3) = -1 EBADF (Bad file descriptor)
...