Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* basic operations with processes, part B, 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 CMDLEN 256
- int main(int argc, char * argv[])
- {
- char cmd[CMDLEN];
- int pid, status, cond;
- cond = 1;
- while(cond > 0) // NOTE: THE LOOP DOES NOT BREAK (presumably because of the char, not char*, declaration?)
- {
- printf("Command ('quit' to leave): ");
- scanf("%s", cmd); // memorises the command input by user
- if(strcmp(cmd, "quit") == 0)
- {
- cond = 0;
- break;
- }
- pid = fork(); // forks the current process
- // if(pid == -1) exit(1);
- if(pid == 0) execlp(cmd, cmd, 0); // if current process is child process, replaces it with the cmd
- else wait(&status); // else, waits until first child death
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement