iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.34k stars 3.86k forks source link

executing hello_world.py in ubuntu 22.04LTS #4307

Open dripcharacter opened 1 year ago

dripcharacter commented 1 year ago

Hi, I am new to bcc. I just setup bcc in ubuntu 22.04 LTS and tried to run hello_world.py in /bcc/examples. In this file, file says that this file will run with 'sudo ./hello_world' in /bcc/examples. But when I tried it, there was error log

'sudo: unable to execute ./hello_world.py: No such file or directory'

So, I tried with 'sudo python3 hello_world.py' and it worked with these logs.

b' systemd-udevd-18460 [001] d...1 15447.848709: bpf_trace_printk: Hello, World!' b'' b' systemd-udevd-33399 [000] d...1 15447.858894: bpf_trace_printk: Hello, World!' b'' b' systemd-udevd-33399 [000] d...1 15447.878289: bpf_trace_printk: Hello, World!' b'' b' systemd-udevd-33399 [000] d...1 15447.893018: bpf_trace_printk: Hello, World!' b'' b' systemd-udevd-33399 [001] d...1 15447.909810: bpf_trace_printk: Hello, World!' b'' b' systemd-udevd-33399 [001] d...1 15447.929566: bpf_trace_printk: Hello, World!' b'' b' systemd-udevd-33399 [001] d...1 15447.952344: bpf_trace_printk: Hello, World!' b'' b' systemd-udevd-33399 [001] d...1 15447.966791: bpf_trace_printk: Hello, World!' b''

But since it didn't exit, I interrupted with ctrl + c. Now I am wonder what was the problem. Does hello world make error since there was some error in my bcc setup, or the command 'sudo ./hello_world.py' was wrong in ubuntu 22.04LTS?

reinierpost commented 1 year ago

The problem is on the first line: #!/usr/bin/python There is no such file on your system.

You can fix this by installing a package: sudo apt install python-is-python3

The script could be changed to use #!/usr/bin/python3, but there may be systems on which that doesn't exist.