LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-14-2008, 07:50 AM   #1
Moraxus
LQ Newbie
 
Registered: Oct 2008
Posts: 26

Rep: Reputation: 15
[C++] Get process ID (PID)


I have window's name, how to get process ID?
On windows there are FindWindow() and GetThreadProcessId() functions, but how to do it on linux?
 
Old 10-14-2008, 08:32 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 492

Rep: Reputation: 50
"getpid" for the process id, "syscall (SYS_gettid)" (or "gettid" if it exists) for the thread id
 
Old 10-14-2008, 10:13 AM   #3
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
I'm not a C or C++ programmer, but just out of curiosity, on UNIX implementations, does fork() return the PID if it is successful?
 
Old 10-14-2008, 01:36 PM   #4
Moraxus
LQ Newbie
 
Registered: Oct 2008
Posts: 26

Original Poster
Rep: Reputation: 15
Thanks for the reply, but i dont want to get current process id, but id of some other process.
How to do it?
 
Old 10-16-2008, 12:00 PM   #5
Moraxus
LQ Newbie
 
Registered: Oct 2008
Posts: 26

Original Poster
Rep: Reputation: 15
I made a little mistake.
On windows to get PID of any process there's GetWindowThreadProcessId function, not GetThreadProcessId.
So how to do it on Linux?
 
Old 10-16-2008, 12:31 PM   #6
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Short answer: not really...

Longer answer: this code *might* help:

http://www.mail-archive.com/devel@xf.../msg05809.html

PS:
It's probably worth remembering that, on Windows, the GUI window and the underlying process are much more tightly coupled than they are under Linux. The Linux "client/server" model, I would argue, is much cleaner and minimizes the need for convolutions like Remote Desktop. IMHO ...

Last edited by paulsm4; 10-16-2008 at 12:34 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to get process status using pid? hongxing Linux - Software 2 04-11-2006 07:11 AM
Getting pid of a process!! vishamr2000 Programming 31 09-09-2005 08:46 PM
how to get more process' info according to its PID? iclinux Programming 1 02-05-2005 05:30 AM
Getting PID of running process in C/C++ laikos Programming 9 03-15-2004 03:33 AM
Get Next PID of Process Tree zer0python Programming 7 11-26-2003 11:56 AM


All times are GMT -5. The time now is 01:53 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration