Questions tagged [strace]

strace is a debugging utility for tracing system calls and signals under Linux.

The most common usage is to start a program using strace, which prints a list of system calls made by the program. This is useful if the program continually crashes, or does not behave as expected; for example using strace may reveal that the program is attempting to access a file which does not exist or cannot be read. Alternatively it can be attached to a process.

Under other OSes it's available with other names, such as DTrace (Solaris) and ktrace (*BSD).

204 questions
88
votes
7 answers

List the files accessed by a program

time is a brilliant command if you want to figure out how much CPU time a given command takes. I am looking for something similar that can list the files being accessed by a program and its children. Either in real time or as a report…
Ole Tange
  • 33,591
  • 31
  • 102
  • 198
57
votes
1 answer

Connecting to IP 0.0.0.0 succeeds. How? Why?

We are serving a port on localhost and want to check in another process if the port is available. Due to a bug in our code, it is actually trying to connect to the IP 0.0.0.0:, and for some reason it succeeds -- as strace…
erikbstack
  • 940
  • 2
  • 9
  • 16
46
votes
1 answer

piping strace to grep

I'm trying to run strace trough ccze, and the pipe doesn't work as expected. The command-line I'm running to test is sudo strace -p $(pgrep apache2) | grep open, and all lines are output, ignoring grep. Is there something special about strace that…
Andrei
  • 1,713
  • 1
  • 15
  • 18
34
votes
4 answers

How to trace networking activity of a command?

I want to trace the networking activity of a command, I tried tcpdump and strace without success. For an example, If I am installing a package or using any command that tries to reach some site, I want to view that networking activity (the site it…
Buvanesh Kumar
  • 533
  • 1
  • 5
  • 11
32
votes
5 answers

What system call is used to load libraries in Linux?

In strace outputs, the paths to the libraries that executables call are in calls to open(). Is this the system call used by executables that are dynamically linked? What about dlopen()? open() isn't a call I'd have guessed would play a role in the…
Melab
  • 3,808
  • 8
  • 29
  • 49
24
votes
1 answer

root cannot write to file that is owned by regular user

I create a file as regular user testuser: $ cat > /tmp/zz the file is owned by that user (as expected): $ ls -lA /tmp/zz -rw------- 1 testuser testuser 0 Feb 20 15:32 zz Now when I try to truncate it as root, I get permission denied: # truncate…
400 the Cat
  • 819
  • 4
  • 37
  • 85
17
votes
1 answer

Tracing executable without read permissions

I found some surprising behavior on Ubuntu 14.04 when using strace on an executable, which I do not have read permission on. I wonder if this is a bug, or if some standard mandates this obscure behavior. First let's see what happens when I start an…
kasperd
  • 3,540
  • 1
  • 20
  • 33
15
votes
3 answers

Is it possible to strace the builtin commands to Bash?

Inspired by this question, titled: When are the built-in commands loaded to memory, while attempting to answer this I tried the following command and was a bit surprised that I couldn't run it: $ strace cd $HOME Is there a method I can make use of…
slm
  • 363,520
  • 117
  • 767
  • 871
15
votes
2 answers

Write strace output to a file

I'm trying to write the output of strace ls to a file. I know that I need to use > in order to forward output of a command to a file, but it doesn't work. It creates a file but the command prints the output of strace ls to stdout but writes the file…
yeled zevel
  • 151
  • 1
  • 1
  • 3
15
votes
1 answer

Where to get "/etc/ld.so.nohwcap" file from?

When I run a command through strace utility I can see access errors such as access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) Now I've read somewhere that what's happening on the above line is that a linker is looking…
Shady Programmer
  • 365
  • 1
  • 3
  • 9
13
votes
1 answer

Executable file named 'test' is in $PATH but won't run

I have a file in $HOME/bin (before you ask, yes, it is in my path) called test which I've confirmed can be executed fine when I run it with the full path to the file. However, I get a really weird issue when I don't run it this way. When I just run…
12
votes
4 answers

What is the time unit that strace uses when displaying time spent in syscalls?

When using the command strace with the flag -T, I would like to know what is the time unit used to display time spent in syscalls? I assume it should be in seconds, but I am not quite sure and it seems to be omitted from the manual.
user311285
  • 131
  • 1
  • 4
12
votes
1 answer

Why doesn't `strace` show this process is waiting for something?

The mighty strace has let me down. How is this possible? time foo shows that foo takes several seconds to run ("real"), but uses negligible cpu time, both in userspace ("user") and in the kernel ("sys"). For the curious, foo is defined below. So…
sourcejedi
  • 48,311
  • 17
  • 143
  • 296
12
votes
2 answers

running strace for specific period of time

How to run strace on a user process for specific period of time, say 1 minute, without terminating the user process and without using Ctrl+C? I want to create a script to automating strace execution for a user process.
adywp
  • 143
  • 1
  • 7
11
votes
1 answer

Bash attempts to write two shell prompts?

I am looking at the strace output of a running bash process connected to a terminal, for educational purposes. My bash process has PID 2883. I type [OP@localhost ~]$ strace -e trace=openat,read,write,fork,vfork,clone,execve -p 2883 2>…
extremeaxe5
  • 1,133
  • 9
  • 19
1
2 3
13 14