LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2012, 03:36 AM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
lua how to get process id?


I know there's no original way to obtain process id in a lua file unless you install additional packages to support, But unfortunately I have no privilege to install additional packages.
I just want to write this process id like number to the log file for indication.
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?
Thanks in advance!
 
Old 05-11-2012, 04:12 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by fantasy1215 View Post
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 View Post
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 ).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lua and Java... ButterflyMelissa Programming 2 04-02-2012 10:07 AM
Conky + lua flyinggeorge Linux - Software 6 03-05-2012 08:47 PM
Trying to get Lua to work with Conky AbsoluteZ3r0 Linux - Software 0 08-17-2011 10:01 AM
Lua not found, yet installed adriv Slackware 20 05-22-2007 11:42 AM
Lua - seperating a string blackman890 Programming 13 03-28-2005 10:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration