Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/user/testbin/pt3/pt3.c
734 views
1
#include <unistd.h>
2
#include <sys/wait.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
6
int main( int argc, char *argv[] ) {
7
pid_t pid;
8
int res;
9
const char *args[] = { "hello", "world", NULL };
10
11
(void)argc;
12
(void)argv;
13
14
pid = fork();
15
if( pid == 0 ) {
16
printf( "Hi. I'm the child. My PID is: %d\n", getpid() );
17
printf( "I'm about to call exec ....\n" );
18
res = execv( "/testbin/pt1", (char **)args );
19
if( res ) {
20
printf( "execv failed." );
21
return -1;
22
}
23
}
24
else {
25
waitpid( pid, &res, 0 );
26
printf( "Hi. I'm the parent. My child returned: %d\n", res );
27
}
28
29
return 0;
30
}
31
32