当父进程在子进程死后读取其退出状态时不使用等待系统调用时,会创建一个Zombie,并且当原始父进程在子进程终止时,孤立是由init回收的子进程.
在内存管理和进程表方面,这些进程的处理方式有何不同,特别是在UNIX中?
当僵尸或孤儿的创建可能对更大的应用程序或系统有害时,有什么例子或极端情况?
这个问题可以作为所有常见问题的参考:
当我将数据复制/扫描到未初始化指针所指向的地址时,为什么会出现神秘崩溃或"分段错误"?
例如:
char* ptr;
strcpy(ptr, "hello world"); // crash here!
Run Code Online (Sandbox Code Playgroud)
要么
char* ptr;
scanf("%s", ptr); // crash here!
Run Code Online (Sandbox Code Playgroud) 我尝试使用C中的scanf()读入2个值,但系统写入内存的值不等于我输入的值.这是代码:
double a,b;
printf("--------\n"); //seperate lines
scanf("%ld",&a);
printf("--------\n");
scanf("%ld",&b);
printf("%d %d",a,b);
Run Code Online (Sandbox Code Playgroud)
如果我输入1和2,CMD返回正确的,但是b = -858993460这是我已经尝试的:使用float或int而不是double,使用scanf_s,使用scanf("%d或%f用于%i或%li或%lf或%e或%g),使用fflush(stdin)清除键盘缓冲区,首先读入b,尝试所有可能的组合.我发现32位操作系统上的双倍长度存在问题,这样你就不得不使用scanf("%lf",&f)读取一个double.无论我做什么,第二个值总是错误的.
我在Windows 7 32位操作系统上使用MS VS express 2012 for Desktop.
我正在写一个C程序中我fork(),exec()和wait().我想把我执行的程序的输出写入文件或缓冲区.
例如,如果我exec ls 我想写入file1 file2 etc缓冲区/文件.我认为没有办法读取标准输出,所以这是否意味着我必须使用管道?这里有一个我无法找到的一般程序吗?
我想编译一下.
program.c
#include <libavcodec/avcodec.h>
int main(){
int i = avpicture_get_size(AV_PIX_FMT_RGB24,300,300);
}
Run Code Online (Sandbox Code Playgroud)
运行这个
gcc -I$HOME/ffmpeg/include program.c
Run Code Online (Sandbox Code Playgroud)
给出错误
/tmp/ccxMLBme.o: In function `main':
program.c:(.text+0x18): undefined reference to `avpicture_get_size'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
但是,定义了avpicture_get_size.为什么会这样?
是否存在将表示端点的"文件"放置到Unix域套接字的约定?
我倾向于把它们放进去/tmp/some-application-specific-subdir-name/,但我想知道是否有一个更常见的地方.
背景是,POSIX不清楚访问这些"文件" 的最大路径长度:
sun_path的大小故意未定义.这是因为不同的实现使用不同的大小.例如,4.3 BSD使用108的大小,4.4 BSD使用104的大小.由于大多数实现源自BSD版本,因此大小通常在92到108的范围内.
应用程序不应假定sun_path的特定长度或假设它可以保存{_POSIX_PATH_MAX}个字节(256).
因此,路径长度上的"限制"应该保留在应用程序的文件/路径名配置之外.
我写了一个基于posix套接字的客户端程序.该程序创建多个线程,并将锁定服务器.但是在gdb时间调试期间,程序会给出一个信息(错误)
Run Code Online (Sandbox Code Playgroud)(gdb) n Program received signal SIGPIPE, Broken pipe. [Switching to Thread 0xb74c0b40 (LWP 4864)] 0xb7fdd424 in __kernel_vsyscall () (gdb)
这是代码:
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int get_hostname_by_ip(char* h , char* ip)
{
struct hostent *he;
struct in_addr **addr_list;
int i;
if ((he = gethostbyname(h)) == NULL)
{
perror("gethostbyname");
return 1;
}
addr_list = (struct in_addr **) he->h_addr_list;
for(i = 0; addr_list[i] != NULL; i++) …Run Code Online (Sandbox Code Playgroud) 在LearnCpp.com上| 1.10 - 首先看一下预处理器.在Header guards下,有一些代码片段:
add.h:
#include "mymath.h"
int add(int x, int y);
Run Code Online (Sandbox Code Playgroud)
subtract.h:
#include "mymath.h"
int subtract(int x, int y);
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
#include "add.h"
#include "subtract.h"
Run Code Online (Sandbox Code Playgroud)
在实施头部防护时,提到如下:
#ifndef ADD_H
#define ADD_H
// your declarations here
#endif
Run Code Online (Sandbox Code Playgroud)
int main()来#endif吗?_H约定还是必须做的事情?谢谢.
每个TCP/IP网络连接的Linux内核(在内核地址空间中)平均消耗多少内存?
我有以下C代码工作:
int ex(unsigned int x) {
int mask = 0x55555555;
int a = ((x >> 0) & mask );
return a + ((x >> 1) & mask );
}
Run Code Online (Sandbox Code Playgroud)
但是,当我将其扩展到此时,我得到了不同的结果:
int ex(unsigned int x) {
int mask = 0x55555555;
int a = ((x >> 0) & mask );
int b = ((x >> 1) & mask );
return a + b;
}
Run Code Online (Sandbox Code Playgroud)
造成这种差异的原因是什么?
编辑:注意,我正在为32位编译.