In Rudin there's an example given to support the necessity of compactness $$f_n(x)=\frac1{1+nx}\ x\in(0,1),$$ which is not uniformly convergent.
My question is if the interval would have been compact i.e. if $x\in[0,1]$ then would $f_n$ be uniformly convergent in the closed interval?
Plz help me with a proper explanation.
Let \begin{equation*}f_n(x)=\frac{1}{1+nx},\ x\in[0,1].\end{equation*} The limit function clearly is \begin{equation*}f(x)=\begin{cases}1&,\text{ if }x=0,\\0&,\text{ if }0<x\le1.\end{cases}.\end{equation*} So, in this extended case, the limit function of this sequence of continuous functions is itself not continuous. Hence, Dini's Theorem says nothing and it is easy to see that the convergence is still not uniform. This might seem unsatisfying, but it is actually completely natural.
If $f_n$ is any monotone sequence of continuous functions that converges pointwise on an open interval $(a,b)$ to a continuous function $f$, but not uniformly (that is, a sequence that is an example to support the necessity of compactness similar to the one Rudin gives) and $\tilde{f_n}$ are continuous extensions of $f_n$ to $[a,b]$ converging pointwise to a function $\tilde{f}$, then the $\tilde{f_n}$ are still monotone and hence $\tilde{f}$ must be discontinuous, for otherwise the convergence on $[a,b]$ would be uniform by Dini's Theorem and hence it's restriction to $(a,b)$ would be uniform contrary to our hypothesis.
The example is still very much a proper one to showcase why the compactness assumption is necessary, because it meets all the other assumptions, yet the conclusion fails. In fact, you can precisely trace back the gap between the theorem and the counter-example in $(0,1)$ by looking at the proof. Rudin constructs a decreasing sequence of compact sets $K_n$ and then uses a well-known theorem on the intersection of such sequences to conclude that this sequence must be eventually empty, which is equivalent to the desired result. For the particular $f_n$ in the example, it is easy to see that $$K_n=(0,1)\cap\left(0,\frac{1-\varepsilon}{\varepsilon n}\right].$$ For reasonably small $\varepsilon$, these are all non-empty, but their intersection is empty, so the reasoning doesn't hold. If you extend this $f_n$ to $[0,1]$, you will see that the $K_n$ are still the same except for possibly containing the point $1$, but the same observations apply. In particular, note that $0\not\in K_n$ corresponds to $f$ having a discontinuity at $0$.