Bruno Santos
Bruno Santos

Reputation: 21

How do I run Valgrind on a program that needs superuser permission?

I'm writing a packet sniffer in C (using libpcap) and I can't use Valgrind to find memory leaks in my program as it must be run with superuser permissions, because, without this, I can't even open the network interface for capture.

When I try to run Valgrind with sudo, I got this:

$ valgrind sudo ./[exec]
==5211== 
==5211== Warning: Can't execute setuid/setgid/setcap executable: /usr/bin/sudo
==5211== Possible workaround: remove --trace-children=yes, if in effect
==5211== 
valgrind: /usr/bin/sudo: Permission denied

So I tried to run as superuser (sudo su) and got this:

# valgrind ./[exec]
valgrind: ./bin/TP2: Permission denied

As well as:

$ sudo valgrind ./[exec]
valgrind: ./bin/TP2: Permission denied

I've searched all the Internet to find an answer for that.

In short, I need to find memory leaks in my packet sniffer and it must be run with admin permissions. Can someone help me with that or, at least, recommend me another memory checker, please?

Upvotes: 1

Views: 5564

Answers (1)

Bruno Santos
Bruno Santos

Reputation: 21

I found a solution. I had no clue that the problem were because the volume which my executable is placed on is a NTFS partition. First I moved the file to a random folder on a Ex4 partition, and so, I had changed permissions on my executable with chmod.

Now I can run Valgrind on my program when logged as root.

Upvotes: 1

Related Questions