Closed immersion definition Hartshorne defines a closed immersion as a morphism $f:Y\longrightarrow X$ of schemes such that 
a) $f$ induces a homeomorphism of $sp(Y)$ onto a closed subset of $sp(X)$, and furthermore 
b) the induced map $f^\#:\mathcal{O}_X\longrightarrow f_* \mathcal{O}_Y$ of sheaves on $X$ is surjective.
My doubt is that why is the condition a) necessary?
Atleast for affine schemes, if $f:(\textrm{Spec}\ B,\mathcal{O}_{\textrm{Spec}\ B})\longrightarrow (\textrm{Spec}\ A,\mathcal{O}_{\textrm{Spec}\ A})$ is a morphism such that condition (b) holds, then we have the stalk level maps are all surjective. But the stalk level maps are all localization maps which will mean that $f^\#_{\mathcal{O}_{\textrm{Spec}\ A}}:A\longrightarrow B$ is itself surjective. But that itself will mean that $f$ is a closed immersion right?
The definition made in Hartshorne must be because this does not carry through for general schemes. But I am not able to think of any example. Any help in this respect will be appreciated.
 A: I figured I would make an answer out the comments to the first answer addressing a point which confused me when I first learned this stuff. A morphism $f:X\to Y$ (I have to write it in this direction or else I'll confuse myself) is said to be a closed immersion if $f$ induces a homeomorphism of $X$ onto a closed subset of $Y$, and $f^\sharp:\mathscr{O}_Y\to f_*(\mathscr{O}_X)$ is surjective.
In some references I've seen it is casually remarked that the second condition is equivalent to surjectivity of the map $f_x^\sharp:\mathscr{O}_{Y,f(x)}\to\mathscr{O}_{X,x}$ for all $x\in X$. But is this really trivial? No! This map, which might reasonably be called the stalk of the morphism $f$ at $x$, is not literally the same as the stalk of $f^\sharp$ at $f(x)$. Indeed, that is a map $f_{f(x)}^\sharp:\mathscr{O}_{Y,f(x)}\to(f_*\mathscr{O}_X)_{f(x)}$. In general, there is always a natural map $\varphi_x:(f_*\mathscr{O}_X)_{f(x)}\to\mathscr{O}_{X,x}$, but it isn't in general an isomorphism. The map $f_x^\sharp$ is equal to $\varphi_x\circ f_{f(x)}^\sharp$. So while it is standard that the map $f^\sharp$ of sheaves (on $Y$!) is surjective if and only if $f_y^\sharp:\mathscr{O}_{Y,y}\to (f_*\mathscr{O}_X)_y$ is surjective for all $y\in Y$, this does not obviously say anything about surjectivity of the maps $f_x^\sharp:\mathscr{O}_{Y,f(x)}\to\mathscr{O}_{X,x}$ for $x\in X$. If however $f$ is a homeomorphism onto a closed subset $f(X)\subseteq Y$, then the stalks of $f_*\mathscr{O}_X$ at points of $Y$ are easy to compute: they are zero at points outside of $f(X)$, and at a point $f(x)\in f(X)$, we have that the natural map $(f_*\mathscr{O}_X)_{f(x)}\to\mathscr{O}_{X,x}$ is an isomorphism. So in that case, surjectivity of each $f_x^\sharp$, $x\in X$, actually will imply surjectivity of $f_y^\sharp$, $y\in Y$, and hence of $f^\sharp$.
Without the condition that $f$ is a closed topological immersion on the underlying topological spaces, it is not going to be true that $f^\sharp$ is surjective if and only if $f_x^\sharp$ is surjective for all $x\in X$. To make this clearer, let's assume $X=\mathrm{Spec}(B)$ and $Y=\mathrm{Spec}(A)$, so $f=\mathrm{Spec}(\alpha)$ for $\alpha:A\to B$ a ring homomorphism. The stalk map of $f$ at $x=\mathfrak{q}\in\mathrm{Spec}(B)$ is the ring map $A_\mathfrak{p}\to B_\mathfrak{q}$, where $\mathfrak{q}=\alpha^{-1}(\mathfrak{p})$. In general, surjectivity of this map for all $\mathfrak{q}\in\mathrm{Spec}(B)$ does not imply surjectivity of $\alpha$ itself.
I think the simplest example that will illustrate this is when $B=A_g$ is a principal localization of $A$. Then in fact the stalk map in the previous paragraph is an isomorphism for every prime ideal of $A_g$ (the set of which are in natural bijection with the set of primes of $A$ not containing $g$, i.e. $D(g)$). But the localization map $A\to A_g$ (i.e. the map on global sections of $f$) is not usually surjective. Note that in this case $f$ is a homeomorphism onto the open subset $D(g)$ of $\mathrm{Spec}(A)$, but $D(g)$ is not generally closed in $A$.
I think maybe this illustrates why the first condition is important, and why, if one wants to think about surjectivity of $f^\sharp$ in terms of the stalks of $f$, $f_x^\sharp$, for $x\in X$, the topological condition is needed, and logically “precedes” the condition on $f^\sharp$.
Lastly, I should note that the maps which I have been calling the “stalks of $f$,” $f_x^\sharp$, for $x\in X$, are in fact the stalks of the map of sheaves on $X$ (in the usual sense) $f^\flat:f^{-1}\mathscr{O}_Y\to \mathscr{O}_X$ corresponding to $f^\sharp$ under the adjunction between $f^{-1}$ and $f_*$. So surjectivity of all $f_x^\sharp$, $x\in X$, is logically equivalent to surjectivity of $f^\flat$. There is no reason to believe that $f^\flat$ is surjective if and only if $f^\sharp$ is, or even that there is an implication in either direction in general.
A: Here is where the confusion lies: Let $\varphi : \mathcal{F} \rightarrow \mathcal{G}$ be a morphism of sheaves on a scheme $X$. Then $\varphi$ is surjective does not mean that for all open $U \subset X$, the morphism $\varphi(U) : \mathcal{F}(U) \rightarrow \mathcal{G}(U)$ is surjective.
See Caution II.1.2.1 of Hartshorne for more details.
