Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* basic operations with processes, UNIX-native */
- /* pointer arithmetics:
- *
- * push(pointer, v) INDICATES *(pointer++) = v
- * pop(pointer) INDICATES *(--pointer)
- * (*++v)[0] INDICATES (**++v)
- * INDICATES first char in v
- * INDICATES name of string/vector v
- * likewise, *v[0] INDICATES **v
- * and *v[n] INDICATES **(v + n)
- * returntype (*funct)(args) INDICATES a function funct with arguments args which returns...
- * char **argv INDICATES pointer to char pointer
- * int(*v)[len] INDICATES pointer "v" to a vector of "len" int elements
- * int *v[len] INDICATES vector "v" of "len" pointers to int elements
- * void *funct() INDICATES function "funct" that returns a pointer-to-void
- * void (*funct)() INDICATES pointer to a function "funct" that returns void
- *
- */
- /* useful characters: [] # */
- # include <stdio.h>
- # include <unistd.h> // execlp is defined here
- # define BUFFERSIZE 1024
- int main(int argc, char * argv[])
- {
- /* PID generation and fork() call */
- int pid = fork(); // process ID is now the ID of the current process
- if(pid == 0) printf("{Call 1} Child process, PID = %d\n", pid);
- else printf("{Call 1} Parent process, PID = %d\n", pid);
- /* process status */
- pid = fork();
- int status; // process status
- if(pid == 0) printf("{Call 2} Child process, PID = %d\n", pid);
- else
- {
- wait(&status); // waits until at least one child terminates
- printf("{Call 2} Parent process, PID = %d\n", pid);
- }
- /* exec* calls */
- execlp("ls", "ls", 0);
- printf("execlp(...) not executed");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement