aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tsh.cc10
-rw-r--r--util.h5
2 files changed, 10 insertions, 5 deletions
diff --git a/tsh.cc b/tsh.cc
index 06cfa2c..fc9b34f 100644
--- a/tsh.cc
+++ b/tsh.cc
@@ -15,8 +15,10 @@
#include <iostream>
#include <vector>
#include <string>
+#include "util.h"
using namespace std;
+using ov4::atomic_print;
/* Misc manifest constants */
#define MAXLINE 1024 /* max line size */
@@ -318,17 +320,15 @@ void waitfg(pid_t pid)
*/
void sigchld_handler(int sig)
{
- constexpr int numlen = 20;
int errno_backup = errno;
int status, pid;
- char msg[] = "sig chld, pid: ", num[numlen];
+ char msg[] = "sig chld, pid: ";
write(STDOUT_FILENO, msg, strlen(msg));
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
{
- // deletejob(NULL, pid);
- sprintf(num, "%d\n", pid);
- write(STDOUT_FILENO, num, strlen(num));
+ deletejob(NULL, pid);
+ atomic_print(pid);
}
diff --git a/util.h b/util.h
index 7fd874d..4ede5bd 100644
--- a/util.h
+++ b/util.h
@@ -13,6 +13,11 @@
namespace ov4 {
+void atomic_print(char *s);
+void atomic_print(int x);
+void reverse(char str[], int length);
+char* itoa(int num, char* str, int base);
+
const int DECIMAL = 10;
const int LENGTH = 20;