Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
why3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
119
Issues
119
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Why3
why3
Commits
b37c8610
Commit
b37c8610
authored
Dec 18, 2010
by
Andrei Paskevich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
retouch cpulimit.c
parent
6890dea1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
31 deletions
+31
-31
Makefile.in
Makefile.in
+3
-1
src/tools/cpulimit.c
src/tools/cpulimit.c
+28
-30
No files found.
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
(
strcmp
(
"-s"
,
argv
[
3
])
==
0
)
{
if
(
showtime
)
{
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