Skip to content

Commit

Permalink
Fix extracting pid form bpf_get_current_pid_tgid lizrice#35
Browse files Browse the repository at this point in the history
According to `man bpf-helpers` pid is located in the lower 32 bits of the return value. Pid can be easily extracted by using an and operation with `0xFFFFFFFF` 

Signed-off-by: Ali Javidi Ghasr <[email protected]>
  • Loading branch information
AliJavidiCS authored Dec 12, 2023
1 parent 207f0d4 commit 71a31cf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion chapter2/hello-buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
struct data_t data = {};
char message[12] = "Hello World";
data.pid = bpf_get_current_pid_tgid() >> 32;
data.pid = bpf_get_current_pid_tgid() & 0xFFFFFFFF;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;
bpf_get_current_comm(&data.command, sizeof(data.command));
Expand Down

0 comments on commit 71a31cf

Please sign in to comment.