Quote:
Originally Posted by fantasy1215
I know there's no original way to obtain process id in a lua
|
Well, if you can read arbitrary files, then reading the first word (number) from
/proc/self/stat will yield the process ID of the process reading the file in Linux.
Quote:
Originally Posted by fantasy1215
I have a multi-process lua engine program to write a single log file. So I want to know if there is another way to write an unique number like process id to the log file?
|
You mean how to obtain an unique ID? In Linux, the best bet for a scripting language is to use the process ID, process group ID, or session ID. All three can be parsed from the
/proc/self/stat file, although the executable name part (in parentheses, but may contain spaces) makes parsing the latter to a bit annoying. The latter two are the same for a family of related processes (forked from the same parent), so they might be useful if you don't want to identify the exact process but the application (group of processes).
See
man 5 proc for details and description of the
/proc/self/stat file (under
/proc/[pid]/stat ).