The tempdb_id() reports the temporary database that a given session is assigned to. The input of the tempdb_id() function is a server process ID, and its output is the temporary database to which the process is assigned. If you do not provide a server process, then tempdb_id() reports the dbid of the temporary database assigned to the current process.
tempdb_id()
Finds all the server processes that are assigned to a given temporary database, execute:
select spid from master..sysprocesses where tempdb_id(spid) = db_id("tempdatabase")
select tempdb_id() gives the same result as select @@tempdbid.