1

I'm working through some homework, and I need to report which system calls a C program makes use of.

I noticed though that exit doesn't show up in strace reports.

#include <stdlib.h>

int main() {
    exit(0);
}

┌─[brendon@parrot]─[~/Desktop/Classes/OSInternals/Lab3]
└──╼ $gcc exit.c
┌─[brendon@parrot]─[~/Desktop/Classes/OSInternals/Lab3]
└──╼ $strace -c ./a.out
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 38.74    0.001056         150         7           mmap
 11.12    0.000303         151         2           openat
 10.20    0.000278         139         2           fstat
 10.09    0.000275         137         2           close
  9.21    0.000251         251         1           arch_prctl
  7.45    0.000203          67         3           mprotect
  6.20    0.000169         169         1           munmap
  5.25    0.000143         143         1           read
  1.76    0.000048          48         1         1 access
  0.00    0.000000           0         1           brk
  0.00    0.000000           0         1           execve
------ ----------- ----------- --------- --------- ----------------
100.00    0.002726                    22         1 total

As you can see, exit doesn't show up in the report. Am I wrong that it's a system call? Reading usr/include/x86_64-linux-gnu/asm/unistd_64.h, I can see an exit entry:

. . .
#define __NR_execve 59
#define __NR_exit 60
#define __NR_wait4 61
. . .

What am I missing here?

Running on Parrot OS.



I was hesitant to post this because it's not clear if this is ontopic enough. I can delete this promptly if it's decided that it's not.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Carcigenicate
  • 43,494
  • 9
  • 68
  • 117

1 Answers1

2

For some reason it doesn't show up in the -c summary but it does show up in the regular strace output:

#include <stdlib.h>

int main(void)
{
    exit(69);
}
$ strace ./exit
execve("./exit", ["./exit"], 0x7ffddc502ce0 /* 42 vars */) = 0
brk(NULL)                               = 0x563a56e63000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=113870, ...}) = 0
mmap(NULL, 113870, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f16c8537000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260A\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1824496, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f16c8535000
mmap(NULL, 1837056, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f16c8374000
mprotect(0x7f16c8396000, 1658880, PROT_NONE) = 0
mmap(0x7f16c8396000, 1343488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f16c8396000
mmap(0x7f16c84de000, 311296, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16a000) = 0x7f16c84de000
mmap(0x7f16c852b000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) = 0x7f16c852b000
mmap(0x7f16c8531000, 14336, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f16c8531000
close(3)                                = 0
arch_prctl(ARCH_SET_FS, 0x7f16c8536500) = 0
mprotect(0x7f16c852b000, 16384, PROT_READ) = 0
mprotect(0x563a565ba000, 4096, PROT_READ) = 0
mprotect(0x7f16c857a000, 4096, PROT_READ) = 0
munmap(0x7f16c8537000, 113870)          = 0
exit_group(69)                          = ?
+++ exited with 69 +++
$ strace -c ./exit 
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
  0.00    0.000000           0         1           read
  0.00    0.000000           0         2           close
  0.00    0.000000           0         2           fstat
  0.00    0.000000           0         7           mmap
  0.00    0.000000           0         4           mprotect
  0.00    0.000000           0         1           munmap
  0.00    0.000000           0         1           brk
  0.00    0.000000           0         1         1 access
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         2           openat
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                    23         1 total

Given that -c measures the time spent in each system call, I guess it doesn't make any sense to measure exit (which never returns).

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Oh, that's odd. I avoided using the verbose output because I figured it was same as `-c`, but just more information, and I'm trying to avoid information overload. I suppose that would have answered it though had I tried. Thank you. I'll leave it open for a bit just in case someone else has anything else to note. – Carcigenicate Jun 07 '20 at 18:01
  • The `-c` option only gives a consolidate summary though, so it doesn't give you any insight into the sequence of system calls. – Jonathon Reinhart Jun 07 '20 at 18:03
  • That's true. I'm not quite at the point where the sequence is necessary (we only just started on Process Management and System Calls), but I'll keep that in mind for when things become more complicated and I need more analysis. – Carcigenicate Jun 07 '20 at 18:06