# compiled for FreeBSD release 12.1-RELEASE-p12; this is 12.2-RELEASE.



## manan7 (Jan 18, 2021)

I'm trying to use lsof but it shows above warning message and also not display output.






On another device:


```
lsof: WARNING: compiled for FreeBSD release 12.1-RELEASE-p12; this is 12.2-RELEASE.
lsof: WARNING: access /root/.lsof_FreeBSD12-2: No such file or directory
lsof: WARNING: created device cache file: /root/.lsof_FreeBSD12-2
COMMAND    PID  USER   FD   TYPE             DEVICE           SIZE/OFF    NODE NAME
```


----------



## DutchDaemon (Jan 18, 2021)

Not an answer, but why not give sockstat(1) a try instead of fitting a square peg into a round hole? Most people use `sockstat -l4` and `sockstat -c4`, coupled with post assignments (`sockstat -l4p22`, `sockstat -c4p443`) for most of the lsof use-cases.


----------



## manan7 (Jan 18, 2021)

DutchDaemon said:


> Not an answer, but why not give sockstat(1) a try instead of fitting a square peg into a round hole?


Thanks for the alternative, but I cannot touch code now. I just wanted to test it.


----------



## DutchDaemon (Jan 18, 2021)

I built it to test:


```
Message from lsof-4.93.2_14,8:

--
NOTE: Due to the way the FreeBSD build clusters make packages,
you may see a warning similar to the following:

lsof: WARNING: compiled for FreeBSD release 11.1-RELEASE-p6; this is 11.1-RELEASE-p4.

This is because the poudriere jails that build the packages don't have the  
corresponding kernel installed, so they don't know that the kernel version is different.

This warning can be ignored if you are using a system that is updated via freebsd-update
and are using pre-built packages.
```

So that part is not problematic, it seems.

Other than that, it just works:


```
# lsof
lsof: WARNING: compiled for FreeBSD release 12.2-RELEASE-p2; this is 12.2-RELEASE-p1.
lsof: WARNING: access /root/.lsof_hostname: No such file or directory
lsof: WARNING: created device cache file: /root/.lsof_hostname
COMMAND     PID         USER   FD     TYPE                DEVICE           SIZE/OFF     NODE NAME
kernel        0         root  cwd     VDIR                 0,120               1024        2 /
kernel        0         root  rtd     VDIR                 0,120               1024        2 /
init          1         root  cwd     VDIR                 0,120               1024        2 /
[etc]
```

_Takes a long time though, because it grabs everything._ Something like `lsof -i TCP:22` is fast.


----------



## manan7 (Jan 18, 2021)

okay, Ya it's working with lsof -i TCP:22. 
but it's taking long time in my code(only lsof) with compare to other o.s., That's why I thought it's not working.

I just kept it run for longer time, after few min it's got killed automatically.


----------



## PMc (Jan 18, 2021)

Yeah, that's normal. That's probably the OOM killer, and You don't have proper swap installed.
I don't know how that lsof thing currently works, even less why, but sometimes it just works normally, and the other time it seems to take forever to produce some output, and when I then look what is going on, I see it bloating into astronomical amouts of memory (multiple GB), until finally the result appears.
Something is certainly going wrong there, and I remember it working better in earlier times, but this is reproducible, and likely should be fixed in the lsof code.


----------

