我已阅读书籍和在线资源,fork()系统调用创建当前进程的副本,并且两个进程从fork()系统调用之后的点开始执行.这是对的吗?
如果它是正确的,为什么下面的代码打印"测试测试"?它应该只打印一次"测试"(通过父进程).
#include <sys/types.h> /* pid_t */
#include <sys/wait.h> /* waitpid */
#include <stdio.h> /* printf, perror */
#include <stdlib.h> /* exit */
#include <unistd.h> /* _exit, fork */
int main(void)
{
int ctr =1;
int pc = 1;
printf("%s", "Test ");
pid_t pidmain = fork();
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud) 更新该引用的同步块中的引用是否有效?例如:
Synchronized(list)
{
list = new ArrayList();
}
Run Code Online (Sandbox Code Playgroud)