PREVILAGED RESOURCE register int a=10; void main() { printf("\n Value of a=%d", a); getch(); }
Created By: Rajeev Ranjan Kumar Tripathi
GETTING PROCESS ID #include<process.h> void main() { printf("\n Process id of this program=%u", getpid()); getch(); }
Created By: Rajeev Ranjan Kumar Tripathi
ABORTING A PROCESS #include <stdio.h> #include <stdlib.h> void finish() { abort(); } int main(void) { printf("\n I am the first and the last message"); finish(); printf("\n I will not be executed anymore"); }
Created By: Rajeev Ranjan Kumar Tripathi
A CHILD PROCESS void main() { printf("\n I am a child process"); }
Created By: Rajeev Ranjan Kumar Tripathi
Syntax of spawnl int spawnl(int mode, char *path, char *argv[]);
Created By: Rajeev Ranjan Kumar Tripathi
PARENT PROCESS (VERSION-1) #include<process.h> #include<stdio.h> void main() { int result; clrscr(); printf("\n Parent process is calling child.exe"); result = spawnl(P_WAIT, "child.exe", NULL); if (result == -1) { perror("Error from spawnl"); } printf("\n Again back in Parent process"); getch(); }
Created By: Rajeev Ranjan Kumar Tripathi
PARENT PROCESS(VERSION-2) #include<process.h> #include<stdio.h> void main() { int result; clrscr(); printf("\n Parent process is calling child.exe"); result = spawnl(P_OVERLAY, "child.exe", NULL); if (result == -1) { perror("Error from spawnl"); } printf("\n Again back in Parent process"); getch(); }
Created By: Rajeev Ranjan Kumar Tripathi
PASSING ARGUMENT TO MAIN METHOD int main(int argc, char *argv[]) { int a, b, c; a=atoi(argv[1]); b=atoi(argv[2]); c=a+b; printf("\nSum=%d",c); }
Created By: Rajeev Ranjan Kumar Tripathi
PASSING ARGUMENTS TO CHILD PROCESS #include<process.h> #include<stdio.h> void main() { int result; char *argv[]={"10","20"}; clrscr(); printf("\n Parent process is calling child.exe"); result = spawnl(P_OVERLAY, "child1.exe",argv); if (result == -1) { perror("Error from spawnl"); } printf("\n Again back in Parent process"); getch(); }
Created By: Rajeev Ranjan Kumar Tripathi
ASSIGNING FUNCTION PRIORITY void before() { clrscr(); printf("\n I will be displayed before main"); } #pragma startup before void main() { printf("\n I am main"); } void after() { printf("\n I will be displayed after main"); getch(); } #pragma exit after