我正在Linux中学习fork(),这是我的程序:
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 int main(void){
5 int pid;
6 pid = fork();
7 if(pid < 0){
8 exit(1);
9 }
10 if(pid == 0){
11 fork();
12 fork();
13 printf("pid:%d ppid:%d\n",getpid(),getppid());
14 exit(0);
15 }
16 else{
17 printf("parent pid:%d ppid:%d\n",getpid(),getppid());
18 exit(0);
19 }
20
21 }
Run Code Online (Sandbox Code Playgroud)
有时效果很好,结果如下:
./test1.out
parent pid:27596 ppid:21425
pid:27599 ppid:27597
pid:27597 ppid:27596
pid:27598 ppid:27597
pid:27600 ppid:27598
Run Code Online (Sandbox Code Playgroud)
但是结果并不一致,通常是这样的:
parent pid:27566 ppid:21425
pid:27567 ppid:27566
pid:27568 ppid:27567
pid:27569 ppid:1599
pid:27570 …
Run Code Online (Sandbox Code Playgroud) 这个问题已经折磨了我两天了,如果没有python3-dev
我就无法安装任何模块,有人可以告诉我如何解决这个问题吗?
The following packages have unmet dependencies:
python3-dev : Depends: python3 (= 3.5.1-3) but 3.5.1-4 is to be installed
Depends: libpython3-dev (= 3.5.1-3) but it is not going to be installed
Depends: python3.5-dev (>= 3.5.1-2~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
Run Code Online (Sandbox Code Playgroud) class Glyph {
void draw() {
print("Glyph.draw()");
}
Glyph() {
print("Glyph() before draw()");
draw();
print("Glyph() after draw()");
}
}
class RoundGlyph extends Glyph{
private int radius = 1;
RoundGlyph(int r){
radius = r;
print("RoundGLyph.draw(), radius = " + radius);
}
void draw(){
print("radius:" + radius);
}
public static void main(String[] args){
new RoundGlyph(5);
}
}
//Glyph() before draw()
radius:0
Glyph() after draw()
RoundGLyph.draw(), radius = 5
Run Code Online (Sandbox Code Playgroud)
代码在上面.
由于draw()不是静态的,因此必须有一个隐含的参数(this).虽然在这种情况下,在Glyph的构造函数中调用draw(),所以我想知道这个"隐式参数"是什么. 据我所知,当我调用tf()时,t为T类型,编译器会把它变成Tf(t).
结果表明,在我看来,它是一个RoundGlyph作为这个参数提供.但这怎么可能?显然,调用draw()时不会创建RoundGlyph.
linux ×2
c ×1
constructor ×1
fork ×1
java ×1
overriding ×1
pip ×1
polymorphism ×1
python ×1
python-3.x ×1
systemd ×1
ubuntu ×1