SPJobDefinition has two constructors
One for web applications:
http://msdn.microsoft.com/en-us/library/ms427704.aspx
And one for services:
http://msdn.microsoft.com/en-us/library/ms461120.aspx
You can attach to the central admin service (like the Health Analysis Job)
Or the Microsoft SharePoint Foundation Timer service (check http://bnedgsp06:8080/_admin/ServiceJobDefinitions.aspx) as it has most of the inbuilt timer jobs
A good example of a farm wide job is: Microsoft.Office.Server.UserProfiles.WSSProfileSyncJob
which has an Execute like this:
public override void Execute()
{
foreach (SPWebApplication application in SPFarm.Local.Services.GetValue<SPWebService>(string.Empty).WebApplications)
{
if (base.JobState.ShouldStop)
{
break;
}
if (!UserProfileServiceProxy.ServiceProxy.ExcludedWebApplications.Contains(application.Id))
{
//do stuff
}
}
}
You can find other global job definitions type names using this powershell:
((get-spfarm).Services |? {$_.TypeName -eq "Microsoft SharePoint Foundation Timer"}).JobDefinitions | select TypeName