~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/slurmd/common/set_oomadj.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************\
 
2
 *  set_oomadj.c - prevent slurmd/slurmstepd from being killed by the
 
3
 *      kernel OOM killer
 
4
 *****************************************************************************
 
5
 *  Written by Hongjia Cao, National University of Defense Technology, China.
 
6
 *  CODE-OCEC-09-009. All rights reserved.
 
7
 *  
 
8
 *  This file is part of SLURM, a resource management program.
 
9
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
10
 *  Please also read the included file: DISCLAIMER.
 
11
 *  
 
12
 *  SLURM is free software; you can redistribute it and/or modify it under
 
13
 *  the terms of the GNU General Public License as published by the Free
 
14
 *  Software Foundation; either version 2 of the License, or (at your option)
 
15
 *  any later version.
 
16
 *
 
17
 *  In addition, as a special exception, the copyright holders give permission 
 
18
 *  to link the code of portions of this program with the OpenSSL library under 
 
19
 *  certain conditions as described in each individual source file, and 
 
20
 *  distribute linked combinations including the two. You must obey the GNU 
 
21
 *  General Public License in all respects for all of the code used other than 
 
22
 *  OpenSSL. If you modify file(s) with this exception, you may extend this 
 
23
 *  exception to your version of the file(s), but you are not obligated to do 
 
24
 *  so. If you do not wish to do so, delete this exception statement from your
 
25
 *  version.  If you delete this exception statement from all source files in 
 
26
 *  the program, then also delete it here.
 
27
 *  
 
28
 *  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
 
29
 *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
30
 *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
31
 *  details.
 
32
 *  
 
33
 *  You should have received a copy of the GNU General Public License along
 
34
 *  with SLURM; if not, write to the Free Software Foundation, Inc.,
 
35
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 
36
\*****************************************************************************/
 
37
 
 
38
#include <errno.h>
 
39
#include <fcntl.h>
 
40
#include <unistd.h>
 
41
#include <stdio.h>
 
42
#include <string.h>
 
43
#include <sys/types.h>
 
44
#include <sys/stat.h>
 
45
#include "src/common/log.h"
 
46
 
 
47
extern int set_oom_adj(int adj)
 
48
{
 
49
        int fd;
 
50
        char oom_adj[16];
 
51
 
 
52
        fd = open("/proc/self/oom_adj", O_WRONLY);
 
53
        if (fd < 0) {
 
54
                if (errno == ENOENT)
 
55
                        debug("failed to open /proc/self/oom_adj: %m");
 
56
                else
 
57
                        error("failed to open /proc/self/oom_adj: %m");
 
58
                return -1;
 
59
        }
 
60
        if (snprintf(oom_adj, 16, "%d", adj) >= 16) {
 
61
                return -1;
 
62
        }
 
63
        while ((write(fd, oom_adj, strlen(oom_adj)) < 0) && (errno == EINTR))
 
64
                ;
 
65
        close(fd);
 
66
 
 
67
        return 0;
 
68
}
 
69
 
 
70