using stat() on an NFS mount

I want to verify a mounted NFS filesystem mountpoint. It's fine if I use stat() while the NFS server is active, but when the server is down for this hard mount, the stat() hangs indefinitely.

So how can I know I will hang without first getting hung? It's a conundrum.

Does your system have getmntent()? That will tell you if the NFS filesystem is mounted.
Also stavfs() is a better choice for filesystem information.

Why do you care? If you hang you should jump for joy. After all, that is the behavior you requested when you mount an NFS filesystem with both the hard and nointr options. If you want different behavior, maybe you should just select the options you actually want.

It is possible to check to get a fairly good idea that an NFS operation should succeed. But this introduces a race condition. You check and see that all is cool. Then the server crashes. Then you try your NFS operation and hang. This is why this approach will never work 100%.

If you really want to go this route, you can use an rpc call to contact the NFS server to inquire of it's health. Calling procedure 0 is a common way to do this. Procedure 0 always succeeds and just exits to prove that the server is alive. The rpcinfo can do this. You can either invoke that program or download the source code from opensolaris to see how to do it.

But I would just set the intr option.