File: rmmpi.c

package info (click to toggle)
openmx 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 325,856 kB
  • ctags: 3,575
  • sloc: ansic: 152,655; f90: 2,080; python: 876; makefile: 675; sh: 25; perl: 18
file content (50 lines) | stat: -rw-r--r-- 968 bytes parent folder | download | duplicates (4)
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char *substr( char *buffer, const char *string,
              int nStart, int nStop );



int main()
{
  static int pid;
  static char st[300],buffer[800];
  static char operate[800];
  FILE *fp;

  sprintf(operate,"ps aux > rmmpi_tmp");
  system(operate);

  if ((fp=fopen("rmmpi_tmp","r"))!=NULL){

    while (fgets(st, 300, fp) != NULL){
      if (strcmp(substr(buffer, st, 0, 5), "ozaki")==0){
        substr(buffer, st, 6, 16);
        pid = atoi(buffer);  
        printf("%s %2d\n",substr(buffer, st, 0, 5),pid);

        sprintf(operate,"kill -9 %2d",pid);
        system(operate);
      } 
    }

    fclose(fp);
  }
  else {
    printf("could not open.\n");
  }

  sprintf(operate,"rm rmmpi_tmp");
  system(operate);

}

char *substr( char *buffer, const char *string, int nStart, int nStop )
{
  memmove( buffer, string + nStart, nStop - nStart );
  buffer[nStop-nStart] = '\0';

  return buffer;
}