※ 引述《cloudyd520.bbs@bbs.cs.nchu.edu.tw (子揚)》之銘言:
> 當FORK()=0時,子程序可以用GETPID()抓取一個PID
> 那要使用哪一個函式可以在子程序裡抓取父函式的
> PID呢?
> int main()
> {
> if (fork()==0)
> {
> printf("This children !CHPID=%d",getpid());
> printf("My parent's PID=%d",??????<=這邊要使用哪個函式?);
> }
> ....
> .....
> return 0;
> }
> OS作業要用><",3Q
你可以在 parent 呼叫 fork() 之前呼叫 getpid(),
然後把結果存在 global variable 裡面,
這樣在 fork() 之後就可以知道 parent 的 pid。
--
Name: Tseng, Ling-hua E-mail Address: uranus@it.muds.net
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Undecided
Homepage: https://it.muds.net/~uranus
--
╔═══╗ ┼────────────────────────╮
║狂狷 ║ │* Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮
║ 年少║ ┼╮ < IP:140.119.164.252 > ╰─╮
╚╦═╦╝ ╰ * From:61-230-216-250.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不馴;屬於年少的輕狂色彩 ◎