-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvi.c
More file actions
executable file
·83 lines (74 loc) · 1.68 KB
/
Copy pathvi.c
File metadata and controls
executable file
·83 lines (74 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<dirent.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/wait.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<time.h>
#include<signal.h>
#include<sys/types.h>
#include<sys/resource.h>
struct stat statRes;
struct rusage usage;
char command[100],cpy_cmd[100];
char home[100],pwd[100],dir[100],user[256],host[256];
int id;
char pidname[1000][200];
int pidnumber;
int pidlst[20000][3];
int pids[1000];
char input_file[100], output_file[100];
int inputD, outputD;
void ls();
void hme();
void pinfo2();
void pd();
void cd();
void username();
void hostname();
void echo();
void vim();
void showpwd();
void printEveryTime();
void history();
void pinfo();
void addTohist();
volatile int total =0;
int pid[10000];
void sig_handler(int signum) {
int pid = waitpid(-1, NULL, WNOHANG);
if(pid > 0){
//printf("Process {%s} Successfully exited with {%d} .\n",pidname[pid],pid);
}
// printf("sig_handler se gaya\n");
}
extern void vi(char *argv[],int len)
{
pid_t cpid;
int *stat;
int status;
printf("%s\n",argv[1]);
pid_t cid = fork();
if(cid==0)
{
//This is the child process.
setpgid(0,0);
execvp(argv[0],argv);
_exit(0);
}
else
{
// fork returns the process id of child to parent and 0 to child process.
// kill(cid, SIGTTOU);
signal(SIGCHLD, sig_handler);
// waitpid(cid, &status, WUNTRACED);
// pidlst[pidnumber][0] = 0;
printf("Cid = %d\n",cid);
pids[pidnumber] = cid;
strcpy(pidname[pidnumber], cpy_cmd);
printf("pidlst = %d\n", pids[pidnumber]);
pidnumber++;
}
}