rename example (test_fork => tests)
This commit is contained in:
parent
78cd455b20
commit
00a4e0e5ab
2 changed files with 15 additions and 6 deletions
|
@ -14,9 +14,9 @@ KEEP_DEBUG = --only-keep-debug
|
||||||
|
|
||||||
default: all
|
default: all
|
||||||
|
|
||||||
all: hello test_fork
|
all: hello tests
|
||||||
|
|
||||||
test_fork: test_fork.o
|
tests: tests.o
|
||||||
$(CC) -T link.ld -o $@ $(LDFLAGS) $<
|
$(CC) -T link.ld -o $@ $(LDFLAGS) $<
|
||||||
$(OBJCOPY) $(KEEP_DEBUG) $@ $@.sym
|
$(OBJCOPY) $(KEEP_DEBUG) $@ $@.sym
|
||||||
$(OBJCOPY) $(STRIP_DEBUG) $@
|
$(OBJCOPY) $(STRIP_DEBUG) $@
|
||||||
|
@ -29,7 +29,7 @@ hello: hello.o
|
||||||
chmod a-x $@.sym
|
chmod a-x $@.sym
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) hello test_fork *.sym *.o *~
|
$(RM) hello tests *.sym *.o *~
|
||||||
|
|
||||||
depend:
|
depend:
|
||||||
$(CC) -MM $(CFLAGS) *.c > Makefile.dep
|
$(CC) -MM $(CFLAGS) *.c > Makefile.dep
|
||||||
|
|
|
@ -22,18 +22,27 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#undef errno
|
#undef errno
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
pid_t pid = fork();
|
int status = 0;
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
printf("Create child process...\n");
|
printf("Create child process...\n");
|
||||||
if (pid == 0) // child
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid == 0) { // child
|
||||||
printf("Hello from child process!\n");
|
printf("Hello from child process!\n");
|
||||||
else
|
exit(42);
|
||||||
|
} else {
|
||||||
printf("Hello from parent process! pid = %u\n", pid);
|
printf("Hello from parent process! pid = %u\n", pid);
|
||||||
|
wait(&status);
|
||||||
|
printf("Child terminated with status %d\n", status);
|
||||||
|
}
|
||||||
|
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue