当前位置: 技术问答>linux和unix
Linux下如何寻找特定窗口
来源: 互联网 发布时间:2015-09-07
本文导语: 刚开始研究Linux,很多概念不了解,说得不清楚希望大家谅解: 比如,用Mozilla打开CSDN的窗口,如何得到其pid?(或者类似Windows下的窗口句柄也行)有没有枚举窗口或者枚举进程的函数? 另外,退化一点,我能不能...
刚开始研究Linux,很多概念不了解,说得不清楚希望大家谅解:
比如,用Mozilla打开CSDN的窗口,如何得到其pid?(或者类似Windows下的窗口句柄也行)有没有枚举窗口或者枚举进程的函数?
另外,退化一点,我能不能在我的程序中新建一个Mozilla进程,并且获得它的pid之类的东西,我能监视这个新的Mozilla的状态?是用fork吗?
最后,希望大家最好能给出详细的代码和注释。
比如,用Mozilla打开CSDN的窗口,如何得到其pid?(或者类似Windows下的窗口句柄也行)有没有枚举窗口或者枚举进程的函数?
另外,退化一点,我能不能在我的程序中新建一个Mozilla进程,并且获得它的pid之类的东西,我能监视这个新的Mozilla的状态?是用fork吗?
最后,希望大家最好能给出详细的代码和注释。
|
1。读取/proc下面以数字命名的目录信息,目录名就是pid
2。看ps源码
2。看ps源码
|
proc目录下面
|
我再怎么说也没有man里面说得清楚,fork在父进程的返回值就是子进程的pid.
#include
main()
{
pid_t ForkPID;
printf("Program start. n");
ForkPID = fork(); /* Create a child and copy the parents
* parent data space, heap and stack.
*/
/* ForkPID == -1 Fork failure.
* == 0 This is the child process.
* > 0 This is the parent process. The number given is the
* PID of the child.
*/
printf("forkPID is %d n", ForkPID); /* Child execution starts here. */
printf("Program end. n");
}
#include
main()
{
pid_t ForkPID;
printf("Program start. n");
ForkPID = fork(); /* Create a child and copy the parents
* parent data space, heap and stack.
*/
/* ForkPID == -1 Fork failure.
* == 0 This is the child process.
* > 0 This is the parent process. The number given is the
* PID of the child.
*/
printf("forkPID is %d n", ForkPID); /* Child execution starts here. */
printf("Program end. n");
}
|
gz
|
man fork
|
up
|
mozilla开一个新窗口不一定会create一个新进程。