70,037
社区成员
发帖
与我相关
我的任务
分享#include "apue.h"
int glob = 6; /*external variable in initialized data */
char buf[] = " a wirte to stdout\n";
int main(void){
int var; /*automatic var on statck*/
pid_t pid;
var = 88;
if( write( STDOUT_FILENO, buf, sizeof(buf) -1 ) != sizeof(buf) -1 )
err_sys( "write error" );
printf( "before fork\n" ); /* donot flush stdout */
if(( pid = fork()) < 0 ){
err_sys( "fork error");
}else if( pid == 0) { /*child*/
glob++;
var++;
}else{
sleep(2);
}
printf("pid = %d, glob = %d, var = %d\n", getpid(), glob, var );
exit(0);
}[oliver@AY1305141850350384fbZ myapue.3e]$ gcc -o 8.1 -l apue 8.1.c
/tmp/ccp4GstY.o: In function `main':
8.1.c:(.text+0x37): undefined reference to `err_sys'
8.1.c:(.text+0x5e): undefined reference to `err_sys'
collect2: ld returned 1 exit status
[oliver@AY1305141850350384fbZ myapue.3e]$[oliver@AY1305141850350384fbZ myapue.3e]$ gcc 8.1.c -l apue -o 8.1
[oliver@AY1305141850350384fbZ myapue.3e]$ ls
11.2.c 14.1.c 8.1 8.1.c[oliver@AY1305141850350384fbZ myapue.3e]$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.