LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-29-2014, 03:58 AM   #1
light-angel
LQ Newbie
 
Registered: Oct 2011
Posts: 1

Rep: Reputation: Disabled
finding PID of a program and saving to file


hi i hope im posting in the right place here

im helping on writing a program with linux and lua @ the mine we have got this in the program

Code:
--// Store PID
if _OS == "Linux" then
	local rfilename = "/proc/self/stat"
	local rfile, err = io.open(rfilename, "r")
	if rfile then
		local msg = rfile:read("*a")
		rfile:close()
		local wfile, err = io.open (_CONFIGDIR.."pidfile", "w")
		if wfile then
			wfile:write(msg)
			wfile:close()
		end
	end
end
and it outputs

Code:
6143 (lua) R 1 6143 6143 0 -1 4202560 828 0 16 0 1 0 0 0 20 0 1 0 205111863 6316032 862 18446744073709551615 134512640 134629472 4292373680 4292363708 4151641136 0 0 4096 17578 0 0 0 17 0 0 0 9 0 0
is their anyway i can just get it to save the PID and nothing else

thanks in advance for your help
 
Old 01-29-2014, 08:09 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
See getpid() for this:

Quote:
GETPID(2) Linux Programmer's Manual GETPID(2)

NAME
getpid, getppid - get process identification

SYNOPSIS
#include <sys/types.h>
#include <unistd.h>

pid_t getpid(void);
pid_t getppid(void);

DESCRIPTION
getpid() returns the process ID of the calling process. (This is often used by routines that generate unique temporary filenames.)

getppid() returns the process ID of the parent of the calling process.
 
  


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
Confluence PID issue. (Removing/clearing stale PID file) vignesh4sh Linux - Server 5 12-05-2012 07:14 AM
Check if a script is already running by saving its PID. Rupadhya Linux - Newbie 2 10-06-2012 08:45 AM
[SOLVED] Finding location of a program with PID known. maobin Linux - Newbie 3 02-23-2011 07:47 PM
Is there a way to make a program create a pid file? blk96gt Slackware 1 10-29-2004 11:59 AM
finding pid with program name durden2.0 Linux - Newbie 1 08-04-2003 08:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:35 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