-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.c
More file actions
45 lines (42 loc) · 868 Bytes
/
Copy pathbackground.c
File metadata and controls
45 lines (42 loc) · 868 Bytes
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
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <pwd.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
extern char *user, *home, *t, *args[20];
extern char temp[30], buff[2], cwd[1000], executable[30], buf2[1000], background[10][20], system_name[10];
extern int back, backpid[10], backcount;
void printBackground()
{
int x;
for (x=0;x<backcount;x++)
{
if (background[x][0]!='\0')
{
if (check_background(backpid[x])==1)
{
printf("%s with pid %d exited normally.\n",background[x],backpid[x]);
background[x][0]='\0';
backpid[x]=0;
}
}
}
}
int check_background(int num)
{
char pid[10];
char path[30] = "/proc/";
pid_t child;
struct stat sts;
sprintf(pid,"%d",num);
strcat(path,pid);
stat(path,&sts);
if (S_ISDIR(sts.st_mode))
return 0;
else
return 1;
}