Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Why3
why3
Commits
b37c8610
Commit
b37c8610
authored
Dec 18, 2010
by
Andrei Paskevich
Browse files
retouch cpulimit.c
parent
6890dea1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Makefile.in
View file @
b37c8610
...
...
@@ -978,7 +978,9 @@ $(DISTRIB_TAR): doc/manual.pdf
headers
:
headache
-c
misc/headache_config.txt
-h
misc/header.txt
\
Makefile.in configure.in
*
/
*
.ml
*
/
*
/
*
.ml
*
/
*
/
*
.ml[ily4]
Makefile.in configure.in src/
*
.ml
*
src/
*
/
*
.ml
*
\
src/tools/cpulimit.c
#########
# myself
...
...
src/tools/cpulimit.c
View file @
b37c8610
/**************************************************************************/
/* */
/* The Why platform for program certification */
/* Copyright (C) 2002-2008 */
/* Romain BARDOU */
/* Jean-Franois COUCHOT */
/* Mehdi DOGGUY */
/* Jean-Christophe FILLITRE */
/* Thierry HUBERT */
/* Claude MARCH */
/* Yannick MOY */
/* Christine PAULIN */
/* Yann RGIS-GIANAS */
/* Nicolas ROUSSET */
/* Xavier URBAIN */
/* Copyright (C) 2010 */
/* François Bobot */
/* Jean-Christophe Filliâtre */
/* Claude Marché */
/* Andrei Paskevich */
/* */
/* This software is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Library General Public */
/* License version 2, with the special exception on linking
*/
/* License version 2
.1
, with the special exception on linking */
/* described in file LICENSE. */
/* */
/* This software is distributed in the hope that it will be useful, */
...
...
@@ -39,36 +31,41 @@
int
main
(
int
argc
,
char
*
argv
[])
{
int
timelimit
,
memlimit
;
int
showtime
,
hidetime
;
struct
rlimit
res
;
if
(
argc
<
5
)
{
fprintf
(
stderr
,
"usage: %s <time limit in seconds> \
<virtual memory limit in MiB> <-s|-h> <command>
\n
\
a null value sets no limit (keeps the actual limit)
\n
"
,
argv
[
0
]);
showtime
=
argc
>=
4
&&
!
strncmp
(
"-s"
,
argv
[
3
],
3
);
hidetime
=
argc
>=
4
&&
!
strncmp
(
"-h"
,
argv
[
3
],
3
);
if
(
argc
<
5
||
!
(
showtime
||
hidetime
))
{
fprintf
(
stderr
,
"usage: %s <time limit in seconds> <virtual memory limit in MiB>
\n
"
" <show/hide cpu time: -s|-h> <command> <args>...
\n\n
"
"Zero sets no limit (keeps the actual limit)
\n
"
,
argv
[
0
]);
return
EXIT_FAILURE
;
}
/* Fork if requested */
if
(
s
trcmp
(
"-s"
,
argv
[
3
])
==
0
)
{
if
(
s
howtime
)
{
int
pid
=
fork
();
if
(
pid
==
-
1
){
if
(
pid
==
-
1
)
{
perror
(
"fork"
);
exit
(
EXIT_FAILURE
);
}
else
if
(
pid
==
0
){
/* The child continues to execute the program */
}
else
{
/* The parent will not exit this condition */
}
if
(
pid
>
0
)
{
int
status
;
waitpid
(
pid
,
&
status
,
0
);
struct
tms
tms
;
double
time
;
waitpid
(
pid
,
&
status
,
0
);
times
(
&
tms
);
double
time
=
(
double
)((
tms
.
tms_cutime
+
tms
.
tms_cstime
+
0
.
0
)
time
=
(
double
)((
tms
.
tms_cutime
+
tms
.
tms_cstime
+
0
.
0
)
/
sysconf
(
_SC_CLK_TCK
));
fprintf
(
stdout
,
"why3cpulimit time : %f s
\n
"
,
time
);
if
(
WIFEXITED
(
status
)){
return
WEXITSTATUS
(
status
);
}
fprintf
(
stdout
,
"why3cpulimit time : %f s
\n
"
,
time
);
if
(
WIFEXITED
(
status
))
return
WEXITSTATUS
(
status
);
kill
(
getpid
(),
SIGTERM
);
}
}
...
...
@@ -97,6 +94,7 @@ a null value sets no limit (keeps the actual limit)\n", argv[0]);
execvp
(
argv
[
4
],
argv
+
4
);
fprintf
(
stderr
,
"%s: exec of '%s' failed (%s)
\n
"
,
argv
[
0
],
argv
[
4
],
strerror
(
errno
));
return
EXIT_FAILURE
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment