What is the correct printf specifier for printing pid_t

Bilal Syed Hussain picture Bilal Syed Hussain · Dec 12, 2013 · Viewed 30.3k times · Source

I'm currently using a explicit cast to long and using %ld for printing pid_t, is there a specifier such as %z for size_t for pid_t?

If not what the best way of printing pid_t?

Answer

Jim Balter picture Jim Balter · Dec 12, 2013

There's no such specifier. I think what you're doing (casting the pid_t to long and printing it with "%ld") is fine; you could use an even wider int type, but there's no implementation where pid_t is bigger than long and probably never will be.