Tweaking slstatus uptime.c for friendlier uptime output

📆 2026-04-29 10:10

One of the small things that always bothered me in slstatus was the default uptime format. It works, but it is a bit too plain for my taste. I wanted something more human-readable: instead of hours and minutes, I wanted uptime displayed as days, hours, and minutes when and if the system's uptime is more than 24 hours.

Example

The tweaking

The idea is simple: check whether the system has been up for more than 24 hours.

If so, split the total hours into days and remaining hours.

First of all we have to create the days variable as an unsigned integer (unsigned means that values cannot be negative). For this we have to modify the line:

and add the day variable d:

Now that we have the days variable (d) we should also do some math and calculate it. We know a day has 24 hours. 1 hour has 3600 seconds. This mean that a day has 24 * 3600 seconds which equals to 86400 seconds.

Now that the math is sorted it's time to apply it:

This just divides the number of seconds the system is up to 86400. We now have days but we're not done yet. Add this line above:

Oh my god, we're almost done. Only this line remains:

It's time to modify it with our new logic and math. We do have days but if we leave it as is the output will be something like:

2 days, 49h 3m

instead of

2 days, 1h 3m

We need to calculate the number of hours remaining if days are present:

See what we did there ? If days (d) is greater than 0 means we have days present. Hours (h) becomes number of hours (h) minus number of days (d) times 24. This means that, if we have 49 hours total uptime, number of days (d) is 2 and hours (h) becomes 1 instead of 49:

49 - ( 2 * 24 ) = 49 - 48 = 1

We have some more magik there as well because of my OCD. Instead of just showing 2d, 1h 3m I opted to show "day" or "days" depending on whever days is 1 or more than 1. The logic is in:

If days (d) is not present we stick to the default output of uptime.c which is:

I rambled a lot trying to explain simple tweaks, time to stop :-). You can see, by looking at the original uptime.c below and the tweaked one, that the changes are small but awesome.

Original uptime.c

Tweaked uptime.c

Why bother?

This is a tiny patch, but it makes uptime much easier to scan in a status bar. Large hour counts like 127h are technically fine, but not very intuitive. That is one of the joys of suckless tools: tiny source code, tiny patches, and behavior exactly how you want it.

slstatus homepage

slstatus source

Screenshot

I almost forgot. Here's a screenshot of my slstatus on my ROG laptop with almost 2 days uptime 👏.

slstatus on ROG laptop

🚶 Back to my blog