# htop in FreeBSD



## Graaf_van_Vlaanderen (Jan 15, 2010)

Currently 'htop' can be used on FreeBSD with the Linux layer. In my opinion it doesn't behave very well.

Would it be possible to make it run directly on FreeBSD. I have no real programming experience, I had some programming courses while
studying engineering (C, Fortran, Pascal, Basic, Assambler,...) at the university.

Although I would see it as a challenge to make this run directly on FreeBSD. So could this be accomplished by a novice in programming and is this technically achievable?


----------



## SirDice (Jan 15, 2010)

Htop leans heavily on linux' /proc. It's quite different from the FreeBSD /proc. You would have to modify the htop source code, remove all the linuxisms and replace it with bsd equivalents. Probably not something a novice can do. It'll be a great way to learn more about linux and freebsd though


----------



## DutchDaemon (Jan 15, 2010)

I don't think htop needs the Linux layer to _run_. All it needs is:


```
***********************************************************
htop(1) requires linprocfs(5) to be mounted. If you don't
have it mounted already, please add this line to /etc/fstab
and run `mount linproc`:
linproc /compat/linux/proc linprocfs rw 0 0
***********************************************************
```

I just built htop on a non-linuxulator machine. All I had to do was create /compat/linux/proc manually.

After making and mounting it, htop ran fine without any Linux compat layer installed anywhere. It does dump a shitload of data in /compat/linux/proc, but other than that, /compat/linux/ is blissfully empty. It does load linprocfs.ko and linux.ko though .. but I have a feeling that linprocfs needs the Linux KLD, not htop itself.

Edit: that observations appears correct:


```
[root@box /etc]# kldunload linprocfs
[root@box /etc]# kldunload linux    
kldunload: can't find file linux
```


----------



## Graaf_van_Vlaanderen (Jan 15, 2010)

DutchDaemon said:
			
		

> I don't think htop needs the Linux layer to _run_. All it needs is:
> 
> 
> ```
> ...



I tried this also and indeed, but it doesn't behave like it should. Check the following sample:

```
1  [||                                  1.3%]     Tasks: 36 total, 1 running
  2  [||                                  2.6%]     Load average: 0.02 0.02 0.02
  Mem[|||                            97/2032MB]     Uptime: 00:18:36
  Swp[                                0/2009MB]

  PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
 7825 depaepe  129   0  7432  2568     0 R 16.0  0.1  0:02.56 htop
 7813 depaepe  128   0  8304  2276     0 S  3.0  0.1  0:02.50 top -uP
  936 root     128   0  5864  1272     0 S  1.0  0.1  0:04.92 /usr/sbin/powerd
 7788 depaepe  128   0 37040  5168     0 S  1.0  0.2  0:00.44 sshd: depaepe@pts/0
 7820 depaepe  128   0 10276  2788     0 S  0.0  0.1  0:00.26 -csh
 7819 depaepe  128   0 37040  5172     0 S  0.0  0.2  0:00.35 sshd: depaepe@pts/3
 7816 root     132   0 37040  5108     0 S  0.0  0.2  0:00.56 sshd: depaepe [priv]
 7809 depaepe  180   0 10276  2756     0 S  0.0  0.1  0:00.32 -csh
 7808 depaepe  133   0 37040  5172     0 S  0.0  0.2  0:00.14 sshd: depaepe@pts/2
 7805 root     131   0 37040  5108     0 S  0.0  0.2  0:00.60 sshd: depaepe [priv]
 7801 depaepe  128   0 10276  2788     0 S  0.0  0.1  0:00.31 -csh
 7800 depaepe  128   0 37040  5172     0 S  0.0  0.2  0:00.14 sshd: depaepe@pts/1
 7795 root     131   0 37040  5108     0 S  0.0  0.2  0:00.57 sshd: depaepe [priv]
 7789 depaepe  128   0 10276  2784     0 S  0.0  0.1  0:00.57 -csh
 7785 root     131   0 37040  5092     0 S  0.0  0.2  0:00.53 sshd: depaepe [priv]
```

As you can see 'htop' seems to consume a lot of resources, while in fact according to the CPU load this is not true. Also when running 'top', 'htop' seems to consume only about 2% CPU load.
Well, I guess I can start looking into it. Maybe the best thing is try to understand how top works...


----------



## SirDice (Jan 15, 2010)

Graaf_van_Vlaanderen said:
			
		

> Well, I guess I can start looking into it. Maybe the best thing is try to understand how top works...


This is one of the reasons why I love FreeBSD :e

http://www.freebsd.org/cgi/cvsweb.cgi/src/contrib/top/top.c


----------



## Graaf_van_Vlaanderen (Jan 16, 2010)

This one looks interesting too:

http://www.unixtop.org/index.shtml

Interesting note:



> The first version of top was completed in the early part of 1984. At that time it only supported one system: a VAX running BSD 4.1.


----------



## fronclynne (Jan 16, 2010)

Graaf_van_Vlaanderen said:
			
		

> 'htop' seems to consume a lot of resources, while in fact according to the CPU load this is not true. Also when running 'top', 'htop' seems to consume only about 2% CPU load.
> Well, I guess I can start looking into it. Maybe the best thing is try to understand how top works...



Here htop says it's using 14-17%, top says htop is using 2-4%; htop says opera is using 5%, top says 0.8%.  I suspect htop is using a different method to calculate CPU use.  Different might also mean spurious, wrong, misleading, or braindead in this case.


----------



## oliverh (Jan 16, 2010)

Graaf_van_Vlaanderen said:
			
		

> This one looks interesting too:
> 
> http://www.unixtop.org/index.shtml
> 
> Interesting note:



FreeBSD uses a port of this UNIX top.

http://www.freebsd.org/cgi/man.cgi?...ion=0&manpath=FreeBSD+8.0-RELEASE&format=html


----------

