Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-14-2008, 08:50 AM   #1
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, 09:32 AM   #2
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
"getpid" for the process id, "syscall (SYS_gettid)" (or "gettid" if it exists) for the thread id
Old 10-14-2008, 11:13 AM   #3
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, 02:36 PM   #4
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, 01:00 PM   #5
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, 01:31 PM   #6
LQ 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:

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 01:34 PM.


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
Getting PID of running process in C/C++ laikos Programming 16 10-30-2015 07:16 PM
Getting pid of a process!! vishamr2000 Programming 34 03-12-2015 08:12 AM
how to get process status using pid? hongxing Linux - Software 2 04-11-2006 08:11 AM
how to get more process' info according to its PID? iclinux Programming 1 02-05-2005 06:30 AM
Get Next PID of Process Tree zer0python Programming 7 11-26-2003 12:56 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 PM.

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